<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Net::HTTP - net: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-Net::HTTP-label-About+the+Examples">About the Examples</a>
    <li><a href="#class-Net::HTTP-label-Strategies">Strategies</a>
    <li><a href="#class-Net::HTTP-label-URIs">URIs</a>
    <li><a href="#class-Net::HTTP-label-Schemes">Schemes</a>
    <li><a href="#class-Net::HTTP-label-Hostnames">Hostnames</a>
    <li><a href="#class-Net::HTTP-label-Paths">Paths</a>
    <li><a href="#class-Net::HTTP-label-Queries">Queries</a>
    <li><a href="#class-Net::HTTP-label-Fragments">Fragments</a>
    <li><a href="#class-Net::HTTP-label-Request+Headers">Request Headers</a>
    <li><a href="#class-Net::HTTP-label-HTTP+Sessions">HTTP Sessions</a>
    <li><a href="#class-Net::HTTP-label-Session+Using+Net-3A-3AHTTP.start">Session Using Net::HTTP.start</a>
    <li><a href="#class-Net::HTTP-label-Session+Using+Net-3A-3AHTTP.start+and+Net-3A-3AHTTP.finish">Session Using Net::HTTP.start and Net::HTTP.finish</a>
    <li><a href="#class-Net::HTTP-label-Single-Request+Session">Single-Request Session</a>
    <li><a href="#class-Net::HTTP-label-HTTP+Requests+and+Responses">HTTP Requests and Responses</a>
    <li><a href="#class-Net::HTTP-label-Following+Redirection">Following Redirection</a>
    <li><a href="#class-Net::HTTP-label-Basic+Authentication">Basic Authentication</a>
    <li><a href="#class-Net::HTTP-label-Streaming+Response+Bodies">Streaming Response Bodies</a>
    <li><a href="#class-Net::HTTP-label-HTTPS">HTTPS</a>
    <li><a href="#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>
    <li><a href="#class-Net::HTTP-label-Proxy+Using+Argument+p_addr+as+a+String">Proxy Using Argument <code>p_addr</code> as a String</a>
    <li><a href="#class-Net::HTTP-label-Proxy+Using+-27ENV-5B-27http_proxy-27-5D-27">Proxy Using ‘<code>ENV[&#39;http_proxy&#39;]</code>’</a>
    <li><a href="#class-Net::HTTP-label-Filtering+Proxies">Filtering Proxies</a>
    <li><a href="#class-Net::HTTP-label-Compression+and+Decompression">Compression and Decompression</a>
    <li><a href="#class-Net::HTTP-label-What-27s+Here">What’s Here</a>
    <li><a href="#class-Net::HTTP-label-Net-3A-3AHTTP+Objects">Net::HTTP Objects</a>
    <li><a href="#class-Net::HTTP-label-Sessions">Sessions</a>
    <li><a href="#class-Net::HTTP-label-Connections">Connections</a>
    <li><a href="#class-Net::HTTP-label-Requests">Requests</a>
    <li><a href="#class-Net::HTTP-label-Responses">Responses</a>
    <li><a href="#class-Net::HTTP-label-Proxies">Proxies</a>
    <li><a href="#class-Net::HTTP-label-Security">Security</a>
    <li><a href="#class-Net::HTTP-label-Addresses+and+Ports">Addresses and Ports</a>
    <li><a href="#class-Net::HTTP-label-HTTP+Version">HTTP Version</a>
    <li><a href="#class-Net::HTTP-label-Debugging">Debugging</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Protocol
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-default_port">::default_port</a>
    <li ><a href="#method-c-get">::get</a>
    <li ><a href="#method-c-get_print">::get_print</a>
    <li ><a href="#method-c-get_response">::get_response</a>
    <li ><a href="#method-c-http_default_port">::http_default_port</a>
    <li ><a href="#method-c-https_default_port">::https_default_port</a>
    <li ><a href="#method-c-is_version_1_2-3F">::is_version_1_2?</a>
    <li class="calls-super" ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-newobj">::newobj</a>
    <li ><a href="#method-c-post">::post</a>
    <li ><a href="#method-c-post_form">::post_form</a>
    <li ><a href="#method-c-proxy_class-3F">::proxy_class?</a>
    <li ><a href="#method-c-start">::start</a>
    <li ><a href="#method-c-version_1_2">::version_1_2</a>
    <li ><a href="#method-c-version_1_2-3F">::version_1_2?</a>
    <li ><a href="#method-i-D">#D</a>
    <li ><a href="#method-i-active-3F">#active?</a>
    <li ><a href="#method-i-addr_port">#addr_port</a>
    <li ><a href="#method-i-begin_transport">#begin_transport</a>
    <li ><a href="#method-i-connect">#connect</a>
    <li ><a href="#method-i-continue_timeout-3D">#continue_timeout=</a>
    <li ><a href="#method-i-copy">#copy</a>
    <li ><a href="#method-i-debug">#debug</a>
    <li ><a href="#method-i-delete">#delete</a>
    <li ><a href="#method-i-do_finish">#do_finish</a>
    <li ><a href="#method-i-do_start">#do_start</a>
    <li ><a href="#method-i-edit_path">#edit_path</a>
    <li ><a href="#method-i-end_transport">#end_transport</a>
    <li ><a href="#method-i-finish">#finish</a>
    <li ><a href="#method-i-get">#get</a>
    <li ><a href="#method-i-get2">#get2</a>
    <li ><a href="#method-i-head">#head</a>
    <li ><a href="#method-i-head2">#head2</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-ipaddr">#ipaddr</a>
    <li ><a href="#method-i-ipaddr-3D">#ipaddr=</a>
    <li ><a href="#method-i-keep_alive-3F">#keep_alive?</a>
    <li ><a href="#method-i-lock">#lock</a>
    <li ><a href="#method-i-max_retries-3D">#max_retries=</a>
    <li ><a href="#method-i-mkcol">#mkcol</a>
    <li ><a href="#method-i-move">#move</a>
    <li ><a href="#method-i-on_connect">#on_connect</a>
    <li ><a href="#method-i-options">#options</a>
    <li ><a href="#method-i-patch">#patch</a>
    <li ><a href="#method-i-peer_cert">#peer_cert</a>
    <li ><a href="#method-i-post">#post</a>
    <li ><a href="#method-i-post2">#post2</a>
    <li ><a href="#method-i-propfind">#propfind</a>
    <li ><a href="#method-i-proppatch">#proppatch</a>
    <li ><a href="#method-i-proxy-3F">#proxy?</a>
    <li ><a href="#method-i-proxy_address">#proxy_address</a>
    <li ><a href="#method-i-proxy_from_env-3F">#proxy_from_env?</a>
    <li ><a href="#method-i-proxy_pass">#proxy_pass</a>
    <li ><a href="#method-i-proxy_port">#proxy_port</a>
    <li ><a href="#method-i-proxy_user">#proxy_user</a>
    <li ><a href="#method-i-proxyaddr">#proxyaddr</a>
    <li ><a href="#method-i-proxyport">#proxyport</a>
    <li ><a href="#method-i-put">#put</a>
    <li ><a href="#method-i-read_timeout-3D">#read_timeout=</a>
    <li ><a href="#method-i-request">#request</a>
    <li ><a href="#method-i-request_get">#request_get</a>
    <li ><a href="#method-i-request_head">#request_head</a>
    <li ><a href="#method-i-request_post">#request_post</a>
    <li ><a href="#method-i-response_body_encoding-3D">#response_body_encoding=</a>
    <li ><a href="#method-i-send_entity">#send_entity</a>
    <li ><a href="#method-i-send_request">#send_request</a>
    <li ><a href="#method-i-set_debug_output">#set_debug_output</a>
    <li ><a href="#method-i-sspi_auth">#sspi_auth</a>
    <li ><a href="#method-i-sspi_auth-3F">#sspi_auth?</a>
    <li ><a href="#method-i-start">#start</a>
    <li ><a href="#method-i-started-3F">#started?</a>
    <li ><a href="#method-i-trace">#trace</a>
    <li ><a href="#method-i-transport_request">#transport_request</a>
    <li ><a href="#method-i-unescape">#unescape</a>
    <li ><a href="#method-i-unlock">#unlock</a>
    <li ><a href="#method-i-use_ssl-3D">#use_ssl=</a>
    <li ><a href="#method-i-use_ssl-3F">#use_ssl?</a>
    <li ><a href="#method-i-write_timeout-3D">#write_timeout=</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Net::HTTP">
    <h1 id="class-Net::HTTP" class="class">
      class Net::HTTP
    </h1>

    <section class="description">
    
<p>Class Net::HTTP provides a rich library that implements the client in a client-server model that uses the HTTP request-response protocol. For information about HTTP, see:</p>
<ul><li>
<p><a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">Hypertext Transfer Protocol</a>.</p>
</li><li>
<p><a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Technical_overview">Technical overview</a>.</p>
</li></ul>

<h2 id="class-Net::HTTP-label-About+the+Examples">About the Examples<span><a href="#class-Net::HTTP-label-About+the+Examples">&para;</a> <a href="#top">&uarr;</a></span></h2>

<h2 id="class-Net::HTTP-label-Strategies">Strategies<span><a href="#class-Net::HTTP-label-Strategies">&para;</a> <a href="#top">&uarr;</a></span></h2>
<ul><li>
<p>If you will make only a few GET requests, consider using OpenURI.</p>
</li><li>
<p>If you will make only a few requests of all kinds, consider using the various singleton convenience methods in this class. Each of the following methods automatically starts and finishes a <a href="HTTP.html#class-Net::HTTP-label-Sessions">session</a> that sends a single request:</p>

<pre class="ruby"><span class="ruby-comment"># Return string response body.</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-identifier">path</span>)
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">uri</span>)

<span class="ruby-comment"># Write string response body to $stdout.</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_print</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-identifier">path</span>)
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_print</span>(<span class="ruby-identifier">uri</span>)

<span class="ruby-comment"># Return response as Net::HTTPResponse object.</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_response</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-identifier">path</span>)
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_response</span>(<span class="ruby-identifier">uri</span>)
<span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;{&quot;title&quot;: &quot;foo&quot;, &quot;body&quot;: &quot;bar&quot;, &quot;userId&quot;: 1}&#39;</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">post</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">data</span>)
<span class="ruby-identifier">params</span> = {<span class="ruby-value">title:</span> <span class="ruby-string">&#39;foo&#39;</span>, <span class="ruby-value">body:</span> <span class="ruby-string">&#39;bar&#39;</span>, <span class="ruby-value">userId:</span> <span class="ruby-value">1</span>}
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">post_form</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">params</span>)
</pre>
</li><li>
<p>If performance is important, consider using sessions, which lower request overhead. This <a href="HTTP.html#class-Net::HTTP-label-Sessions">session</a> has multiple requests for <a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods">HTTP methods</a> and <a href="https://en.wikipedia.org/wiki/WebDAV#Implementation">WebDAV methods</a>:</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">hostname</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
  <span class="ruby-comment"># Session started automatically before block execution.</span>
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">head</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-identifier">body</span> = <span class="ruby-string">&#39;Some text&#39;</span>
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">post</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>)  <span class="ruby-comment"># Can also have a block.</span>
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">put</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">options</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">trace</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">patch</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>) <span class="ruby-comment"># Can also have a block.</span>
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">copy</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">lock</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">mkcol</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">move</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">propfind</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proppatch</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">unlock</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>)
  <span class="ruby-comment"># Session finished automatically at block exit.</span>
<span class="ruby-keyword">end</span>
</pre>
</li></ul>

<p>The methods cited above are convenience methods that, via their few arguments, allow minimal control over the requests. For greater control, consider using <a href="HTTPRequest.html">request objects</a>.</p>

<h2 id="class-Net::HTTP-label-URIs">URIs<span><a href="#class-Net::HTTP-label-URIs">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>On the internet, a URI (<a href="https://en.wikipedia.org/wiki/Uniform_Resource_Identifier">Universal Resource Identifier</a>) is a string that identifies a particular resource. It consists of some or all of: scheme, hostname, path, query, and fragment; see <a href="https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax">URI syntax</a>.</p>

<p>A Ruby URI::Generic object represents an internet URI. It provides, among others, methods <code>scheme</code>, <code>hostname</code>, <code>path</code>, <code>query</code>, and <code>fragment</code>.</p>

<h3 id="class-Net::HTTP-label-Schemes">Schemes<span><a href="#class-Net::HTTP-label-Schemes">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>An internet URI has a <a href="https://en.wikipedia.org/wiki/List_of_URI_schemes">scheme</a>.</p>

<p>The two schemes supported in Net::HTTP are <code>&#39;https&#39;</code> and <code>&#39;http&#39;</code>:</p>

<pre class="ruby"><span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span>                       <span class="ruby-comment"># =&gt; &quot;https&quot;</span>
<span class="ruby-constant">URI</span>(<span class="ruby-string">&#39;http://example.com&#39;</span>).<span class="ruby-identifier">scheme</span> <span class="ruby-comment"># =&gt; &quot;http&quot;</span>
</pre>

<h3 id="class-Net::HTTP-label-Hostnames">Hostnames<span><a href="#class-Net::HTTP-label-Hostnames">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>A hostname identifies a server (host) to which requests may be sent:</p>

<pre class="ruby"><span class="ruby-identifier">hostname</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">hostname</span> <span class="ruby-comment"># =&gt; &quot;jsonplaceholder.typicode.com&quot;</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">hostname</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
  <span class="ruby-comment"># Some HTTP stuff.</span>
<span class="ruby-keyword">end</span>
</pre>

<h3 id="class-Net::HTTP-label-Paths">Paths<span><a href="#class-Net::HTTP-label-Paths">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>A host-specific path identifies a resource on the host:</p>

<pre class="ruby"><span class="ruby-identifier">_uri</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">dup</span>
<span class="ruby-identifier">_uri</span>.<span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;/todos/1&#39;</span>
<span class="ruby-identifier">hostname</span> = <span class="ruby-identifier">_uri</span>.<span class="ruby-identifier">hostname</span>
<span class="ruby-identifier">path</span> = <span class="ruby-identifier">_uri</span>.<span class="ruby-identifier">path</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-identifier">path</span>)
</pre>

<h3 id="class-Net::HTTP-label-Queries">Queries<span><a href="#class-Net::HTTP-label-Queries">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>A host-specific query adds name/value pairs to the URI:</p>

<pre class="ruby"><span class="ruby-identifier">_uri</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">dup</span>
<span class="ruby-identifier">params</span> = {<span class="ruby-value">userId:</span> <span class="ruby-value">1</span>, <span class="ruby-value">completed:</span> <span class="ruby-keyword">false</span>}
<span class="ruby-identifier">_uri</span>.<span class="ruby-identifier">query</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">encode_www_form</span>(<span class="ruby-identifier">params</span>)
<span class="ruby-identifier">_uri</span> <span class="ruby-comment"># =&gt; #&lt;URI::HTTPS https://jsonplaceholder.typicode.com?userId=1&amp;completed=false&gt;</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">_uri</span>)
</pre>

<h3 id="class-Net::HTTP-label-Fragments">Fragments<span><a href="#class-Net::HTTP-label-Fragments">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>A <a href="https://en.wikipedia.org/wiki/URI_fragment">URI fragment</a> has no effect in Net::HTTP; the same data is returned, regardless of whether a fragment is included.</p>

<h2 id="class-Net::HTTP-label-Request+Headers">Request Headers<span><a href="#class-Net::HTTP-label-Request+Headers">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Request headers may be used to pass additional information to the host, similar to arguments passed in a method call; each header is a name/value pair.</p>

<p>Each of the Net::HTTP methods that sends a request to the host has optional argument <code>headers</code>, where the headers are expressed as a hash of field-name/value pairs:</p>

<pre class="ruby"><span class="ruby-identifier">headers</span> = {<span class="ruby-value">Accept:</span> <span class="ruby-string">&#39;application/json&#39;</span>, <span class="ruby-value">Connection:</span> <span class="ruby-string">&#39;Keep-Alive&#39;</span>}
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">headers</span>)
</pre>

<p>See lists of both standard request fields and common request fields at <a href="https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields">Request Fields</a>. A host may also accept other custom fields.</p>

<h2 id="class-Net::HTTP-label-HTTP+Sessions">HTTP Sessions<span><a href="#class-Net::HTTP-label-HTTP+Sessions">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>A <em>session</em> is a connection between a server (host) and a client that:</p>
<ul><li>
<p>Is begun by instance method <a href="HTTP.html#method-i-start"><code>Net::HTTP#start</code></a>.</p>
</li><li>
<p>May contain any number of requests.</p>
</li><li>
<p>Is ended by instance method <a href="HTTP.html#method-i-finish"><code>Net::HTTP#finish</code></a>.</p>
</li></ul>

<p>See example sessions at <a href="HTTP.html#class-Net::HTTP-label-Strategies">Strategies</a>.</p>

<h3 id="class-Net::HTTP-label-Session+Using+Net-3A-3AHTTP.start">Session Using Net::HTTP.start<span><a href="#class-Net::HTTP-label-Session+Using+Net-3A-3AHTTP.start">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>If you have many requests to make to a single host (and port), consider using singleton method <a href="HTTP.html#method-c-start"><code>Net::HTTP.start</code></a> with a block; the method handles the session automatically by:</p>
<ul><li>
<p>Calling <a href="HTTP.html#method-i-start"><code>start</code></a> before block execution.</p>
</li><li>
<p>Executing the block.</p>
</li><li>
<p>Calling <a href="HTTP.html#method-i-finish"><code>finish</code></a> after block execution.</p>
</li></ul>

<p>In the block, you can use these instance methods, each of which that sends a single request:</p>
<ul><li>
<p><a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods">HTTP methods</a>:</p>
<ul><li>
<p><a href="HTTP.html#method-i-get"><code>get</code></a>, <a href="HTTP.html#method-i-request_get"><code>request_get</code></a>: GET.</p>
</li><li>
<p><a href="HTTP.html#method-i-head"><code>head</code></a>, <a href="HTTP.html#method-i-request_head"><code>request_head</code></a>: HEAD.</p>
</li><li>
<p><a href="HTTP.html#method-i-post"><code>post</code></a>, <a href="HTTP.html#method-i-request_post"><code>request_post</code></a>: POST.</p>
</li><li>
<p><a href="HTTP.html#method-i-delete"><code>delete</code></a>: DELETE.</p>
</li><li>
<p><a href="HTTP.html#method-i-options"><code>options</code></a>: OPTIONS.</p>
</li><li>
<p><a href="HTTP.html#method-i-trace"><code>trace</code></a>: TRACE.</p>
</li><li>
<p><a href="HTTP.html#method-i-patch"><code>patch</code></a>: PATCH.</p>
</li></ul>
</li><li>
<p><a href="https://en.wikipedia.org/wiki/WebDAV#Implementation">WebDAV methods</a>:</p>
<ul><li>
<p><a href="HTTP.html#method-i-copy"><code>copy</code></a>: COPY.</p>
</li><li>
<p><a href="HTTP.html#method-i-lock"><code>lock</code></a>: LOCK.</p>
</li><li>
<p><a href="HTTP.html#method-i-mkcol"><code>mkcol</code></a>: MKCOL.</p>
</li><li>
<p><a href="HTTP.html#method-i-move"><code>move</code></a>: MOVE.</p>
</li><li>
<p><a href="HTTP.html#method-i-propfind"><code>propfind</code></a>: PROPFIND.</p>
</li><li>
<p><a href="HTTP.html#method-i-proppatch"><code>proppatch</code></a>: PROPPATCH.</p>
</li><li>
<p><a href="HTTP.html#method-i-unlock"><code>unlock</code></a>: UNLOCK.</p>
</li></ul>
</li></ul>

<h3 id="class-Net::HTTP-label-Session+Using+Net-3A-3AHTTP.start+and+Net-3A-3AHTTP.finish">Session Using Net::HTTP.start and Net::HTTP.finish<span><a href="#class-Net::HTTP-label-Session+Using+Net-3A-3AHTTP.start+and+Net-3A-3AHTTP.finish">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>You can manage a session manually using methods <a href="HTTP.html#method-i-start"><code>start</code></a> and <a href="HTTP.html#method-i-finish"><code>finish</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">start</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&#39;/todos/2&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-string">&#39;/posts/1&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">finish</span> <span class="ruby-comment"># Needed to free resources.</span>
</pre>

<h3 id="class-Net::HTTP-label-Single-Request+Session">Single-Request Session<span><a href="#class-Net::HTTP-label-Single-Request+Session">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Certain convenience methods automatically handle a session by:</p>
<ul><li>
<p>Creating an HTTP object</p>
</li><li>
<p>Starting a session.</p>
</li><li>
<p>Sending a single request.</p>
</li><li>
<p>Finishing the session.</p>
</li><li>
<p>Destroying the object.</p>
</li></ul>

<p>Such methods that send GET requests:</p>
<ul><li>
<p><a href="HTTP.html#method-c-get"><code>::get</code></a>: Returns the string response body.</p>
</li><li>
<p><a href="HTTP.html#method-c-get_print"><code>::get_print</code></a>: Writes the string response body to $stdout.</p>
</li><li>
<p><a href="HTTP.html#method-c-get_response"><code>::get_response</code></a>: Returns a <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a> object.</p>
</li></ul>

<p>Such methods that send POST requests:</p>
<ul><li>
<p><a href="HTTP.html#method-c-post"><code>::post</code></a>: Posts data to the host.</p>
</li><li>
<p><a href="HTTP.html#method-c-post_form"><code>::post_form</code></a>: Posts form data to the host.</p>
</li></ul>

<h2 id="class-Net::HTTP-label-HTTP+Requests+and+Responses">HTTP Requests and Responses<span><a href="#class-Net::HTTP-label-HTTP+Requests+and+Responses">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Many of the methods above are convenience methods, each of which sends a request and returns a string without directly using Net::HTTPRequest and Net::HTTPResponse objects.</p>

<p>You can, however, directly create a request object, send the request, and retrieve the response object; see:</p>
<ul><li>
<p><a href="HTTPRequest.html"><code>Net::HTTPRequest</code></a>.</p>
</li><li>
<p><a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>
</li></ul>

<h2 id="class-Net::HTTP-label-Following+Redirection">Following Redirection<span><a href="#class-Net::HTTP-label-Following+Redirection">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Each returned response is an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>. See the <a href="HTTPResponse.html#class-Net::HTTPResponse-label-Response+Subclasses">response class hierarchy</a>.</p>

<p>In particular, class <a href="HTTPRedirection.html"><code>Net::HTTPRedirection</code></a> is the parent of all redirection classes. This allows you to craft a case statement to handle redirections properly:</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">fetch</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">limit</span> = <span class="ruby-value">10</span>)
  <span class="ruby-comment"># You should choose a better exception.</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&#39;Too many HTTP redirects&#39;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">limit</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>

  <span class="ruby-identifier">res</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_response</span>(<span class="ruby-constant">URI</span>(<span class="ruby-identifier">uri</span>))
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">res</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPSuccess</span>     <span class="ruby-comment"># Any success class.</span>
    <span class="ruby-identifier">res</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPRedirection</span> <span class="ruby-comment"># Any redirection class.</span>
    <span class="ruby-identifier">location</span> = <span class="ruby-identifier">res</span>[<span class="ruby-string">&#39;Location&#39;</span>]
    <span class="ruby-identifier">warn</span> <span class="ruby-node">&quot;Redirected to #{location}&quot;</span>
    <span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">location</span>, <span class="ruby-identifier">limit</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
  <span class="ruby-keyword">else</span>                      <span class="ruby-comment"># Any other class.</span>
    <span class="ruby-identifier">res</span>.<span class="ruby-identifier">value</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">uri</span>)
</pre>

<h2 id="class-Net::HTTP-label-Basic+Authentication">Basic Authentication<span><a href="#class-Net::HTTP-label-Basic+Authentication">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Basic authentication is performed according to <a href="http://www.ietf.org/rfc/rfc2617.txt">RFC2617</a>:</p>

<pre class="ruby"><span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>)
<span class="ruby-identifier">req</span>.<span class="ruby-identifier">basic_auth</span>(<span class="ruby-string">&#39;user&#39;</span>, <span class="ruby-string">&#39;pass&#39;</span>)
<span class="ruby-identifier">res</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">hostname</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>)
<span class="ruby-keyword">end</span>
</pre>

<h2 id="class-Net::HTTP-label-Streaming+Response+Bodies">Streaming Response Bodies<span><a href="#class-Net::HTTP-label-Streaming+Response+Bodies">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>By default Net::HTTP reads an entire response into memory.  If you are handling large files or wish to implement a progress bar you can instead stream the body directly to an IO.</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">hostname</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">open</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-string">&#39;w&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">res</span>.<span class="ruby-identifier">read_body</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">chunk</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">chunk</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<h2 id="class-Net::HTTP-label-HTTPS">HTTPS<span><a href="#class-Net::HTTP-label-HTTPS">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>HTTPS is enabled for an HTTP connection by <a href="HTTP.html#method-i-use_ssl-3D"><code>Net::HTTP#use_ssl=</code></a>:</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-value">:use_ssl</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-keyword">true</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>)
  <span class="ruby-identifier">res</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>)
<span class="ruby-keyword">end</span>
</pre>

<p>Or if you simply want to make a GET request, you may pass in a URI object that has an HTTPS URL. Net::HTTP automatically turns on TLS verification if the URI object has a ‘https’ URI scheme:</p>

<pre class="ruby"><span class="ruby-identifier">uri</span> <span class="ruby-comment"># =&gt; #&lt;URI::HTTPS https://jsonplaceholder.typicode.com/&gt;</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">uri</span>)
</pre>

<h2 id="class-Net::HTTP-label-Proxy+Server">Proxy Server<span><a href="#class-Net::HTTP-label-Proxy+Server">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>An HTTP object can have a <a href="https://en.wikipedia.org/wiki/Proxy_server">proxy server</a>.</p>

<p>You can create an HTTP object with a proxy server using method <a href="HTTP.html#method-c-new"><code>Net::HTTP.new</code></a> or method <a href="HTTP.html#method-c-start"><code>Net::HTTP.start</code></a>.</p>

<p>The proxy may be defined either by argument <code>p_addr</code> or by environment variable <code>&#39;http_proxy&#39;</code>.</p>

<h3 id="class-Net::HTTP-label-Proxy+Using+Argument+p_addr+as+a+String">Proxy Using Argument <code>p_addr</code> as a String<span><a href="#class-Net::HTTP-label-Proxy+Using+Argument+p_addr+as+a+String">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>When argument <code>p_addr</code> is a string hostname, the returned <code>http</code> has the given host as its proxy:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&#39;proxy.example&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy?</span>          <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_from_env?</span> <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span>   <span class="ruby-comment"># =&gt; &quot;proxy.example&quot;</span>
<span class="ruby-comment"># These use default values.</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_port</span>      <span class="ruby-comment"># =&gt; 80</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_user</span>      <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_pass</span>      <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p>The port, username, and password for the proxy may also be given:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&#39;proxy.example&#39;</span>, <span class="ruby-value">8000</span>, <span class="ruby-string">&#39;pname&#39;</span>, <span class="ruby-string">&#39;ppass&#39;</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTP jsonplaceholder.typicode.com:80 open=false&gt;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy?</span>          <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_from_env?</span> <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span>   <span class="ruby-comment"># =&gt; &quot;proxy.example&quot;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_port</span>      <span class="ruby-comment"># =&gt; 8000</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_user</span>      <span class="ruby-comment"># =&gt; &quot;pname&quot;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_pass</span>      <span class="ruby-comment"># =&gt; &quot;ppass&quot;</span>
</pre>

<h3 id="class-Net::HTTP-label-Proxy+Using+-27ENV-5B-27http_proxy-27-5D-27">Proxy Using ‘<code>ENV[&#39;http_proxy&#39;]</code>’<span><a href="#class-Net::HTTP-label-Proxy+Using+-27ENV-5B-27http_proxy-27-5D-27">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>When environment variable <code>&#39;http_proxy&#39;</code> is set to a URI string, the returned <code>http</code> will have the server at that URI as its proxy; note that the URI string must have a protocol such as <code>&#39;http&#39;</code> or <code>&#39;https&#39;</code>:</p>

<pre class="ruby"><span class="ruby-constant">ENV</span>[<span class="ruby-string">&#39;http_proxy&#39;</span>] = <span class="ruby-string">&#39;http://example.com&#39;</span>
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy?</span>          <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_from_env?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span>   <span class="ruby-comment"># =&gt; &quot;example.com&quot;</span>
<span class="ruby-comment"># These use default values.</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_port</span>      <span class="ruby-comment"># =&gt; 80</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_user</span>      <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_pass</span>      <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p>The URI string may include proxy username, password, and port number:</p>

<pre class="ruby"><span class="ruby-constant">ENV</span>[<span class="ruby-string">&#39;http_proxy&#39;</span>] = <span class="ruby-string">&#39;http://pname:ppass@example.com:8000&#39;</span>
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy?</span>          <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_from_env?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span>   <span class="ruby-comment"># =&gt; &quot;example.com&quot;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_port</span>      <span class="ruby-comment"># =&gt; 8000</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_user</span>      <span class="ruby-comment"># =&gt; &quot;pname&quot;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_pass</span>      <span class="ruby-comment"># =&gt; &quot;ppass&quot;</span>
</pre>

<h3 id="class-Net::HTTP-label-Filtering+Proxies">Filtering Proxies<span><a href="#class-Net::HTTP-label-Filtering+Proxies">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>With method <a href="HTTP.html#method-c-new"><code>Net::HTTP.new</code></a> (but not <a href="HTTP.html#method-c-start"><code>Net::HTTP.start</code></a>), you can use argument <code>p_no_proxy</code> to filter proxies:</p>
<ul><li>
<p>Reject a certain address:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;example.com&#39;</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&#39;proxy.example&#39;</span>, <span class="ruby-value">8000</span>, <span class="ruby-string">&#39;pname&#39;</span>, <span class="ruby-string">&#39;ppass&#39;</span>, <span class="ruby-string">&#39;proxy.example&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span> <span class="ruby-comment"># =&gt; nil</span>
</pre>
</li><li>
<p>Reject certain domains or subdomains:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;example.com&#39;</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&#39;my.proxy.example&#39;</span>, <span class="ruby-value">8000</span>, <span class="ruby-string">&#39;pname&#39;</span>, <span class="ruby-string">&#39;ppass&#39;</span>, <span class="ruby-string">&#39;proxy.example&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span> <span class="ruby-comment"># =&gt; nil</span>
</pre>
</li><li>
<p>Reject certain addresses and port combinations:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;example.com&#39;</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&#39;proxy.example&#39;</span>, <span class="ruby-value">8000</span>, <span class="ruby-string">&#39;pname&#39;</span>, <span class="ruby-string">&#39;ppass&#39;</span>, <span class="ruby-string">&#39;proxy.example:1234&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span> <span class="ruby-comment"># =&gt; &quot;proxy.example&quot;</span>

<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;example.com&#39;</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&#39;proxy.example&#39;</span>, <span class="ruby-value">8000</span>, <span class="ruby-string">&#39;pname&#39;</span>, <span class="ruby-string">&#39;ppass&#39;</span>, <span class="ruby-string">&#39;proxy.example:8000&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span> <span class="ruby-comment"># =&gt; nil</span>
</pre>
</li><li>
<p>Reject a list of the types above delimited using a comma:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;example.com&#39;</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&#39;proxy.example&#39;</span>, <span class="ruby-value">8000</span>, <span class="ruby-string">&#39;pname&#39;</span>, <span class="ruby-string">&#39;ppass&#39;</span>, <span class="ruby-string">&#39;my.proxy,proxy.example:8000&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span> <span class="ruby-comment"># =&gt; nil</span>

<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;example.com&#39;</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&#39;my.proxy&#39;</span>, <span class="ruby-value">8000</span>, <span class="ruby-string">&#39;pname&#39;</span>, <span class="ruby-string">&#39;ppass&#39;</span>, <span class="ruby-string">&#39;my.proxy,proxy.example:8000&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span> <span class="ruby-comment"># =&gt; nil</span>
</pre>
</li></ul>

<h2 id="class-Net::HTTP-label-Compression+and+Decompression">Compression and Decompression<span><a href="#class-Net::HTTP-label-Compression+and+Decompression">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Net::HTTP does not compress the body of a request before sending.</p>

<p>By default, Net::HTTP adds header <code>&#39;Accept-Encoding&#39;</code> to a new <a href="HTTPRequest.html">request object</a>:</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>)[<span class="ruby-string">&#39;Accept-Encoding&#39;</span>]
<span class="ruby-comment"># =&gt; &quot;gzip;q=1.0,deflate;q=0.6,identity;q=0.3&quot;</span>
</pre>

<p>This requests the server to zip-encode the response body if there is one; the server is not required to do so.</p>

<p>Net::HTTP does not automatically decompress a response body if the response has header <code>&#39;Content-Range&#39;</code>.</p>

<p>Otherwise decompression (or not) depends on the value of header <a href="https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#content-encoding-response-header">Content-Encoding</a>:</p>
<ul><li>
<p><code>&#39;deflate&#39;</code>, <code>&#39;gzip&#39;</code>, or <code>&#39;x-gzip&#39;</code>: decompresses the body and deletes the header.</p>
</li><li>
<p><code>&#39;none&#39;</code> or <code>&#39;identity&#39;</code>: does not decompress the body, but deletes the header.</p>
</li><li>
<p>Any other value: leaves the body and header unchanged.</p>
</li></ul>

<h2 id="class-Net::HTTP-label-What-27s+Here">What’s Here<span><a href="#class-Net::HTTP-label-What-27s+Here">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>This is a categorized summary of methods and attributes.</p>

<h3 id="class-Net::HTTP-label-Net-3A-3AHTTP+Objects">Net::HTTP Objects<span><a href="#class-Net::HTTP-label-Net-3A-3AHTTP+Objects">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="HTTP.html#method-c-new">::new</a>: Creates a new instance.</p>
</li><li>
<p><a href="HTTP.html#method-i-inspect">#inspect</a>: Returns a string representation of <code>self</code>.</p>
</li></ul>

<h3 id="class-Net::HTTP-label-Sessions">Sessions<span><a href="#class-Net::HTTP-label-Sessions">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="HTTP.html#method-c-start">::start</a>: Begins a new session in a new Net::HTTP object.</p>
</li><li>
<p><a href="HTTP.html#method-i-started-3F">#started?</a> (aliased as <a href="HTTP.html#method-i-active-3F">#active?</a>): Returns whether in a session.</p>
</li><li>
<p><a href="HTTP.html#method-i-finish">#finish</a>: Ends an active session.</p>
</li><li>
<p><a href="HTTP.html#method-i-start">#start</a>: Begins a new session in an existing Net::HTTP object (<code>self</code>).</p>
</li></ul>

<h3 id="class-Net::HTTP-label-Connections">Connections<span><a href="#class-Net::HTTP-label-Connections">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="HTTP.html#attribute-i-continue_timeout">:continue_timeout</a>: Returns the continue timeout.</p>
</li><li>
<p><a href="HTTP.html#method-i-continue_timeout-3D">#continue_timeout=</a>: Sets the continue timeout seconds.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-keep_alive_timeout">:keep_alive_timeout</a>: Returns the keep-alive timeout.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-keep_alive_timeout">:keep_alive_timeout=</a>: Sets the keep-alive timeout.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-max_retries">:max_retries</a>: Returns the maximum retries.</p>
</li><li>
<p><a href="HTTP.html#method-i-max_retries-3D">#max_retries=</a>: Sets the maximum retries.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-open_timeout">:open_timeout</a>: Returns the open timeout.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-open_timeout">:open_timeout=</a>: Sets the open timeout.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-read_timeout">:read_timeout</a>: Returns the open timeout.</p>
</li><li>
<p><a href="HTTP.html#method-i-read_timeout-3D">:read_timeout=</a>: Sets the read timeout.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ssl_timeout">:ssl_timeout</a>: Returns the ssl timeout.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ssl_timeout">:ssl_timeout=</a>: Sets the ssl timeout.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-write_timeout">:write_timeout</a>: Returns the write timeout.</p>
</li><li>
<p><a href="HTTP.html#method-i-write_timeout-3D">write_timeout=</a>: Sets the write timeout.</p>
</li></ul>

<h3 id="class-Net::HTTP-label-Requests">Requests<span><a href="#class-Net::HTTP-label-Requests">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="HTTP.html#method-c-get">::get</a>: Sends a GET request and returns the string response body.</p>
</li><li>
<p><a href="HTTP.html#method-c-get_print">::get_print</a>: Sends a GET request and write the string response body to $stdout.</p>
</li><li>
<p><a href="HTTP.html#method-c-get_response">::get_response</a>: Sends a GET request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-c-post_form">::post_form</a>: Sends a POST request with form data and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-c-post">::post</a>: Sends a POST request with data and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-copy">#copy</a>: Sends a COPY request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-delete">#delete</a>: Sends a DELETE request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-get">#get</a>: Sends a GET request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-head">#head</a>: Sends a HEAD request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-lock">#lock</a>: Sends a LOCK request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-mkcol">#mkcol</a>: Sends a MKCOL request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-move">#move</a>: Sends a MOVE request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-options">#options</a>: Sends a OPTIONS request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-patch">#patch</a>: Sends a PATCH request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-post">#post</a>: Sends a POST request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-propfind">#propfind</a>: Sends a PROPFIND request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-proppatch">#proppatch</a>: Sends a PROPPATCH request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-put">#put</a>: Sends a PUT request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-request">#request</a>: Sends a request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-request_get">#request_get</a> (aliased as <a href="HTTP.html#method-i-get2">#get2</a>): Sends a GET request and forms a response object; if a block given, calls the block with the object, otherwise returns the object.</p>
</li><li>
<p><a href="HTTP.html#method-i-request_head">#request_head</a> (aliased as <a href="HTTP.html#method-i-head2">#head2</a>): Sends a HEAD request and forms a response object; if a block given, calls the block with the object, otherwise returns the object.</p>
</li><li>
<p><a href="HTTP.html#method-i-request_post">#request_post</a> (aliased as <a href="HTTP.html#method-i-post2">#post2</a>): Sends a POST request and forms a response object; if a block given, calls the block with the object, otherwise returns the object.</p>
</li><li>
<p><a href="HTTP.html#method-i-send_request">#send_request</a>: Sends a request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-trace">#trace</a>: Sends a TRACE request and returns a response object.</p>
</li><li>
<p><a href="HTTP.html#method-i-unlock">#unlock</a>: Sends an UNLOCK request and returns a response object.</p>
</li></ul>

<h3 id="class-Net::HTTP-label-Responses">Responses<span><a href="#class-Net::HTTP-label-Responses">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="HTTP.html#attribute-i-close_on_empty_response">:close_on_empty_response</a>: Returns whether to close connection on empty response.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-close_on_empty_response">:close_on_empty_response=</a>: Sets whether to close connection on empty response.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ignore_eof">:ignore_eof</a>: Returns whether to ignore end-of-file when reading a response body with <code>Content-Length</code> headers.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ignore_eof">:ignore_eof=</a>: Sets whether to ignore end-of-file when reading a response body with <code>Content-Length</code> headers.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-response_body_encoding">:response_body_encoding</a>: Returns the encoding to use for the response body.</p>
</li><li>
<p><a href="HTTP.html#method-i-response_body_encoding-3D">#response_body_encoding=</a>: Sets the response body encoding.</p>
</li></ul>

<h3 id="class-Net::HTTP-label-Proxies">Proxies<span><a href="#class-Net::HTTP-label-Proxies">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="HTTP.html#method-i-proxy_address">:proxy_address</a>: Returns the proxy address.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-proxy_address">:proxy_address=</a>: Sets the proxy address.</p>
</li><li>
<p><a href="HTTP.html#method-c-proxy_class-3F">::proxy_class?</a>: Returns whether <code>self</code> is a proxy class.</p>
</li><li>
<p><a href="HTTP.html#method-i-proxy-3F">#proxy?</a>: Returns whether <code>self</code> has a proxy.</p>
</li><li>
<p><a href="HTTP.html#method-i-proxy_address">#proxy_address</a> (aliased as <a href="HTTP.html#method-i-proxyaddr">#proxyaddr</a>): Returns the proxy address.</p>
</li><li>
<p><a href="HTTP.html#method-i-proxy_from_env-3F">#proxy_from_env?</a>: Returns whether the proxy is taken from an environment variable.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-proxy_from_env">:proxy_from_env=</a>: Sets whether the proxy is to be taken from an environment variable.</p>
</li><li>
<p><a href="HTTP.html#method-i-proxy_pass">:proxy_pass</a>: Returns the proxy password.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-proxy_pass">:proxy_pass=</a>: Sets the proxy password.</p>
</li><li>
<p><a href="HTTP.html#method-i-proxy_port">:proxy_port</a>: Returns the proxy port.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-proxy_port">:proxy_port=</a>: Sets the proxy port.</p>
</li><li>
<p><a href="HTTP.html#method-i-proxy_user">#proxy_user</a>: Returns the proxy user name.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-proxy_user">:proxy_user=</a>: Sets the proxy user.</p>
</li></ul>

<h3 id="class-Net::HTTP-label-Security">Security<span><a href="#class-Net::HTTP-label-Security">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="HTTP.html#attribute-i-ca_file">:ca_file</a>: Returns the path to a CA certification file.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ca_file">:ca_file=</a>: Sets the path to a CA certification file.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ca_path">:ca_path</a>: Returns the path of to CA directory containing certification files.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ca_path">:ca_path=</a>: Sets the path of to CA directory containing certification files.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-cert">:cert</a>: Returns the OpenSSL::X509::Certificate object to be used for client certification.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-cert">:cert=</a>: Sets the OpenSSL::X509::Certificate object to be used for client certification.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-cert_store">:cert_store</a>: Returns the X509::Store to be used for verifying peer certificate.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-cert_store">:cert_store=</a>: Sets the X509::Store to be used for verifying peer certificate.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ciphers">:ciphers</a>: Returns the available SSL ciphers.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ciphers">:ciphers=</a>: Sets the available SSL ciphers.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-extra_chain_cert">:extra_chain_cert</a>: Returns the extra X509 certificates to be added to the certificate chain.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-extra_chain_cert">:extra_chain_cert=</a>: Sets the extra X509 certificates to be added to the certificate chain.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-key">:key</a>: Returns the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-key">:key=</a>: Sets the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-max_version">:max_version</a>: Returns the maximum SSL version.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-max_version">:max_version=</a>: Sets the maximum SSL version.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-min_version">:min_version</a>: Returns the minimum SSL version.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-min_version">:min_version=</a>: Sets the minimum SSL version.</p>
</li><li>
<p><a href="HTTP.html#method-i-peer_cert">#peer_cert</a>: Returns the X509 certificate chain for the session’s socket peer.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ssl_version">:ssl_version</a>: Returns the SSL version.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-ssl_version">:ssl_version=</a>: Sets the SSL version.</p>
</li><li>
<p><a href="HTTP.html#method-i-use_ssl-3D">#use_ssl=</a>: Sets whether a new session is to use Transport Layer Security.</p>
</li><li>
<p><a href="HTTP.html#method-i-use_ssl-3F">#use_ssl?</a>: Returns whether <code>self</code> uses SSL.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_callback">:verify_callback</a>: Returns the callback for the server certification verification.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_callback">:verify_callback=</a>: Sets the callback for the server certification verification.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_depth">:verify_depth</a>: Returns the maximum depth for the certificate chain verification.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_depth">:verify_depth=</a>: Sets the maximum depth for the certificate chain verification.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_hostname">:verify_hostname</a>: Returns the flags for server the certification verification at the beginning of the SSL/TLS session.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_hostname">:verify_hostname=</a>: Sets he flags for server the certification verification at the beginning of the SSL/TLS session.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_mode">:verify_mode</a>: Returns the flags for server the certification verification at the beginning of the SSL/TLS session.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_mode">:verify_mode=</a>: Sets the flags for server the certification verification at the beginning of the SSL/TLS session.</p>
</li></ul>

<h3 id="class-Net::HTTP-label-Addresses+and+Ports">Addresses and Ports<span><a href="#class-Net::HTTP-label-Addresses+and+Ports">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="HTTP.html#attribute-i-address">:address</a>: Returns the string host name or host IP.</p>
</li><li>
<p><a href="HTTP.html#method-c-default_port">::default_port</a>: Returns integer 80, the default port to use for <a href="HTTP.html"><code>HTTP</code></a> requests.</p>
</li><li>
<p><a href="HTTP.html#method-c-http_default_port">::http_default_port</a>: Returns integer 80, the default port to use for <a href="HTTP.html"><code>HTTP</code></a> requests.</p>
</li><li>
<p><a href="HTTP.html#method-c-https_default_port">::https_default_port</a>: Returns integer 443, the default port to use for HTTPS requests.</p>
</li><li>
<p><a href="HTTP.html#method-i-ipaddr">#ipaddr</a>: Returns the IP address for the connection.</p>
</li><li>
<p><a href="HTTP.html#method-i-ipaddr-3D">#ipaddr=</a>: Sets the IP address for the connection.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-local_host">:local_host</a>: Returns the string local host used to establish the connection.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-local_host">:local_host=</a>: Sets the string local host used to establish the connection.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-local_port">:local_port</a>: Returns the integer local port used to establish the connection.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-local_port">:local_port=</a>: Sets the integer local port used to establish the connection.</p>
</li><li>
<p><a href="HTTP.html#attribute-i-port">:port</a>: Returns the integer port number.</p>
</li></ul>

<h3 id="class-Net::HTTP-label-HTTP+Version">HTTP Version<span><a href="#class-Net::HTTP-label-HTTP+Version">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="HTTP.html#method-c-version_1_2-3F">::version_1_2?</a> (aliased as <a href="HTTP.html#method-c-is_version_1_2-3F">::is_version_1_2?</a> and <a href="HTTP.html#method-c-version_1_2">::version_1_2</a>): Returns true; retained for compatibility.</p>
</li></ul>

<h3 id="class-Net::HTTP-label-Debugging">Debugging<span><a href="#class-Net::HTTP-label-Debugging">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="HTTP.html#method-i-set_debug_output">#set_debug_output</a>: Sets the output stream for debugging.</p>
</li></ul>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">



        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-c-proxy_address" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">proxy_address</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the address of the proxy host, or <code>nil</code> if none; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server at <code>Net::HTTP</code></a>.</p>
              </div>
            </div>
          <div id="attribute-c-proxy_pass" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">proxy_pass</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the password for accessing the proxy, or <code>nil</code> if none; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server at <code>Net::HTTP</code></a>.</p>
              </div>
            </div>
          <div id="attribute-c-proxy_port" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">proxy_port</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the port number of the proxy host, or <code>nil</code> if none; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server at <code>Net::HTTP</code></a>.</p>
              </div>
            </div>
          <div id="attribute-c-proxy_user" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">proxy_user</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the user name for accessing the proxy, or <code>nil</code> if none; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server at <code>Net::HTTP</code></a>.</p>
              </div>
            </div>
          <div id="attribute-i-address" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">address</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the string host name or host IP given as argument <code>address</code> in <a href="HTTP.html#method-c-new"><code>::new</code></a>.</p>
              </div>
            </div>
          <div id="attribute-i-ca_file" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">ca_file</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the path to a CA certification file in PEM format.</p>
              </div>
            </div>
          <div id="attribute-i-ca_path" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">ca_path</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the path of to CA directory containing certification files in PEM format.</p>
              </div>
            </div>
          <div id="attribute-i-cert" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">cert</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the OpenSSL::X509::Certificate object to be used for client certification.</p>
              </div>
            </div>
          <div id="attribute-i-cert_store" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">cert_store</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the X509::Store to be used for verifying peer certificate.</p>
              </div>
            </div>
          <div id="attribute-i-ciphers" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">ciphers</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the available SSL ciphers. See OpenSSL::SSL::SSLContext#ciphers=.</p>
              </div>
            </div>
          <div id="attribute-i-close_on_empty_response" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">close_on_empty_response</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns whether to close the connection when the response is empty; initially <code>false</code>.</p>
              </div>
            </div>
          <div id="attribute-i-continue_timeout" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">continue_timeout</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the continue timeout value; see <a href="HTTP.html#attribute-i-continue_timeout"><code>continue_timeout</code></a>=.</p>
              </div>
            </div>
          <div id="attribute-i-extra_chain_cert" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">extra_chain_cert</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the extra X509 certificates to be added to the certificate chain. See OpenSSL::SSL::SSLContext#add_certificate.</p>
              </div>
            </div>
          <div id="attribute-i-ignore_eof" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">ignore_eof</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns whether to ignore end-of-file when reading a response body with <code>Content-Length</code> headers; initially <code>true</code>.</p>
              </div>
            </div>
          <div id="attribute-i-keep_alive_timeout" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">keep_alive_timeout</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the numeric (Integer or Float) number of seconds to keep the connection open after a request is sent; initially 2. If a new request is made during the given interval, the still-open connection is used; otherwise the connection will have been closed and a new connection is opened.</p>
              </div>
            </div>
          <div id="attribute-i-key" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">key</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.</p>
              </div>
            </div>
          <div id="attribute-i-local_host" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">local_host</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the string local host used to establish the connection; initially <code>nil</code>.</p>
              </div>
            </div>
          <div id="attribute-i-local_port" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">local_port</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the integer local port used to establish the connection; initially <code>nil</code>.</p>
              </div>
            </div>
          <div id="attribute-i-max_retries" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">max_retries</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the maximum number of times to retry an idempotent request; see <a href="HTTP.html#method-i-max_retries-3D"><code>max_retries=</code></a>.</p>
              </div>
            </div>
          <div id="attribute-i-max_version" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">max_version</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the maximum SSL version. See OpenSSL::SSL::SSLContext#max_version=.</p>
              </div>
            </div>
          <div id="attribute-i-min_version" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">min_version</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the minimum SSL version. See OpenSSL::SSL::SSLContext#min_version=.</p>
              </div>
            </div>
          <div id="attribute-i-open_timeout" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">open_timeout</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the numeric (Integer or Float) number of seconds to wait for a connection to open; initially 60. If the connection is not made in the given interval, an exception is raised.</p>
              </div>
            </div>
          <div id="attribute-i-port" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">port</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the integer port number given as argument <code>port</code> in <a href="HTTP.html#method-c-new"><code>::new</code></a>.</p>
              </div>
            </div>
          <div id="attribute-i-proxy_address" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">proxy_address</span><span
                class="attribute-access-type">[W]</span>
            </div>

            <div class="method-description">
              <p>Sets the proxy address; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>
              </div>
            </div>
          <div id="attribute-i-proxy_from_env" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">proxy_from_env</span><span
                class="attribute-access-type">[W]</span>
            </div>

            <div class="method-description">
              <p>Sets whether to determine the proxy from environment variable ‘<code>ENV[&#39;http_proxy&#39;]</code>’; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Using+-27ENV-5B-27http_proxy-27-5D-27">Proxy Using ENV[‘http_proxy’]</a>.</p>
              </div>
            </div>
          <div id="attribute-i-proxy_pass" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">proxy_pass</span><span
                class="attribute-access-type">[W]</span>
            </div>

            <div class="method-description">
              <p>Sets the proxy password; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>
              </div>
            </div>
          <div id="attribute-i-proxy_port" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">proxy_port</span><span
                class="attribute-access-type">[W]</span>
            </div>

            <div class="method-description">
              <p>Sets the proxy port; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>
              </div>
            </div>
          <div id="attribute-i-proxy_user" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">proxy_user</span><span
                class="attribute-access-type">[W]</span>
            </div>

            <div class="method-description">
              <p>Sets the proxy user; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>
              </div>
            </div>
          <div id="attribute-i-read_timeout" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">read_timeout</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the numeric (Integer or Float) number of seconds to wait for one block to be read (via one read(2) call); see <a href="HTTP.html#method-i-read_timeout-3D"><code>read_timeout=</code></a>.</p>
              </div>
            </div>
          <div id="attribute-i-response_body_encoding" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">response_body_encoding</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the encoding to use for the response body; see <a href="HTTP.html#method-i-response_body_encoding-3D"><code>response_body_encoding=</code></a>.</p>
              </div>
            </div>
          <div id="attribute-i-ssl_timeout" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">ssl_timeout</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the SSL timeout seconds.</p>
              </div>
            </div>
          <div id="attribute-i-ssl_version" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">ssl_version</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the SSL version. See OpenSSL::SSL::SSLContext#ssl_version=.</p>
              </div>
            </div>
          <div id="attribute-i-verify_callback" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">verify_callback</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the callback for the server certification verification.</p>
              </div>
            </div>
          <div id="attribute-i-verify_depth" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">verify_depth</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the maximum depth for the certificate chain verification.</p>
              </div>
            </div>
          <div id="attribute-i-verify_hostname" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">verify_hostname</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns whether to verify that the server certificate is valid for the hostname. See OpenSSL::SSL::SSLContext#verify_hostname=.</p>
              </div>
            </div>
          <div id="attribute-i-verify_mode" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">verify_mode</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>Sets or returns the flags for server the certification verification at the beginning of the SSL/TLS session. OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER are acceptable.</p>
              </div>
            </div>
          <div id="attribute-i-write_timeout" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">write_timeout</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Returns the numeric (Integer or Float) number of seconds to wait for one block to be written (via one write(2) call); see <a href="HTTP.html#method-i-write_timeout-3D"><code>write_timeout=</code></a>.</p>
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-default_port" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">default_port</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns integer <code>80</code>, the default port to use for HTTP requests:</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">default_port</span> <span class="ruby-comment"># =&gt; 80</span>
</pre>

                              <div class="method-source-code" id="default_port-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 901</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">default_port</span>
  <span class="ruby-identifier">http_default_port</span>()
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-get" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          Net::HTTP.get(hostname, path, port = 80) &rarr; body
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          Net::HTTP:get(uri, headers = {}, port = uri.port) &rarr; body
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Sends a GET request and returns the HTTP response body as a string.</p>

<p>With string arguments <code>hostname</code> and <code>path</code>:</p>

<pre class="ruby"><span class="ruby-identifier">hostname</span> = <span class="ruby-string">&#39;jsonplaceholder.typicode.com&#39;</span>
<span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;/todos/1&#39;</span>
<span class="ruby-identifier">puts</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-identifier">path</span>)
</pre>

<p>Output:</p>

<pre class="ruby">{
  <span class="ruby-value">&quot;userId&quot;:</span> <span class="ruby-value">1</span>,
  <span class="ruby-value">&quot;id&quot;:</span> <span class="ruby-value">1</span>,
  <span class="ruby-value">&quot;title&quot;:</span> <span class="ruby-string">&quot;delectus aut autem&quot;</span>,
  <span class="ruby-value">&quot;completed&quot;:</span> <span class="ruby-keyword">false</span>
}
</pre>

<p>With URI object <code>uri</code> and optional hash argument <code>headers</code>:</p>

<pre class="ruby"><span class="ruby-identifier">uri</span> = <span class="ruby-constant">URI</span>(<span class="ruby-string">&#39;https://jsonplaceholder.typicode.com/todos/1&#39;</span>)
<span class="ruby-identifier">headers</span> = {<span class="ruby-string">&#39;Content-type&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;application/json; charset=UTF-8&#39;</span>}
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">headers</span>)
</pre>

<p>Related:</p>
<ul><li>
<p><a href="HTTP/Get.html"><code>Net::HTTP::Get</code></a>: request class for HTTP method <code>GET</code>.</p>
</li><li>
<p><a href="HTTP.html#method-i-get"><code>Net::HTTP#get</code></a>: convenience method for HTTP method <code>GET</code>.</p>
</li></ul>

                              <div class="method-source-code" id="get-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 803</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">get</span>(<span class="ruby-identifier">uri_or_host</span>, <span class="ruby-identifier">path_or_headers</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">port</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">get_response</span>(<span class="ruby-identifier">uri_or_host</span>, <span class="ruby-identifier">path_or_headers</span>, <span class="ruby-identifier">port</span>).<span class="ruby-identifier">body</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-get_print" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          Net::HTTP.get_print(hostname, path, port = 80) &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          Net::HTTP:get_print(uri, headers = {}, port = uri.port) &rarr; nil
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Like <a href="HTTP.html#method-c-get"><code>Net::HTTP.get</code></a>, but writes the returned body to $stdout; returns <code>nil</code>.</p>

                              <div class="method-source-code" id="get_print-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 762</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">get_print</span>(<span class="ruby-identifier">uri_or_host</span>, <span class="ruby-identifier">path_or_headers</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">port</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">get_response</span>(<span class="ruby-identifier">uri_or_host</span>, <span class="ruby-identifier">path_or_headers</span>, <span class="ruby-identifier">port</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">res</span>.<span class="ruby-identifier">read_body</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">chunk</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-identifier">chunk</span>
    <span class="ruby-keyword">end</span>
  }
  <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-get_response" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          Net::HTTP.get_response(hostname, path, port = 80) &rarr; http_response
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          Net::HTTP:get_response(uri, headers = {}, port = uri.port) &rarr; http_response
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Like <a href="HTTP.html#method-c-get"><code>Net::HTTP.get</code></a>, but returns a <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a> object instead of the body string.</p>

                              <div class="method-source-code" id="get_response-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 813</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">get_response</span>(<span class="ruby-identifier">uri_or_host</span>, <span class="ruby-identifier">path_or_headers</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">port</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">path_or_headers</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">path_or_headers</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
    <span class="ruby-identifier">host</span> = <span class="ruby-identifier">uri_or_host</span>
    <span class="ruby-identifier">path</span> = <span class="ruby-identifier">path_or_headers</span>
    <span class="ruby-identifier">new</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span> <span class="ruby-operator">||</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">default_port</span>).<span class="ruby-identifier">start</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request_get</span>(<span class="ruby-identifier">path</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
    }
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">uri</span> = <span class="ruby-identifier">uri_or_host</span>
    <span class="ruby-identifier">headers</span> = <span class="ruby-identifier">path_or_headers</span>
    <span class="ruby-identifier">start</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">hostname</span>, <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">port</span>,
          <span class="ruby-value">:use_ssl</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;https&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request_get</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">headers</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
    }
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-http_default_port" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">http_default_port</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns integer <code>80</code>, the default port to use for HTTP requests:</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">http_default_port</span> <span class="ruby-comment"># =&gt; 80</span>
</pre>

                              <div class="method-source-code" id="http_default_port-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 909</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">http_default_port</span>
  <span class="ruby-value">80</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-https_default_port" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">https_default_port</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns integer <code>443</code>, the default port to use for HTTPS requests:</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">https_default_port</span> <span class="ruby-comment"># =&gt; 443</span>
</pre>

                              <div class="method-source-code" id="https_default_port-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 917</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">https_default_port</span>
  <span class="ruby-value">443</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-is_version_1_2-3F" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">is_version_1_2?</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HTTP.html#method-c-version_1_2-3F">version_1_2?</a>
                            </div>
                          </div>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, p_no_proxy = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new Net::HTTP object <code>http</code> (but does not open a TCP connection or HTTP session).</p>

<p>With only string argument <code>address</code> given (and <code>ENV[&#39;http_proxy&#39;]</code> undefined or <code>nil</code>), the returned <code>http</code>:</p>
<ul><li>
<p>Has the given address.</p>
</li><li>
<p>Has the default port number, <a href="HTTP.html#method-c-default_port"><code>Net::HTTP.default_port</code></a> (80).</p>
</li><li>
<p>Has no proxy.</p>
</li></ul>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTP jsonplaceholder.typicode.com:80 open=false&gt;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">address</span> <span class="ruby-comment"># =&gt; &quot;jsonplaceholder.typicode.com&quot;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">port</span>    <span class="ruby-comment"># =&gt; 80</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy?</span>  <span class="ruby-comment"># =&gt; false</span>
</pre>

<p>With integer argument <code>port</code> also given, the returned <code>http</code> has the given port:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>, <span class="ruby-value">8000</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTP jsonplaceholder.typicode.com:8000 open=false&gt;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">port</span> <span class="ruby-comment"># =&gt; 8000</span>
</pre>

<p>For proxy-defining arguments <code>p_addr</code> through <code>p_no_proxy</code>, see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1066</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">new</span>(<span class="ruby-identifier">address</span>, <span class="ruby-identifier">port</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">p_addr</span> = <span class="ruby-value">:ENV</span>, <span class="ruby-identifier">p_port</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">p_user</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">p_pass</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">p_no_proxy</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">http</span> = <span class="ruby-keyword">super</span> <span class="ruby-identifier">address</span>, <span class="ruby-identifier">port</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">proxy_class?</span> <span class="ruby-keyword">then</span> <span class="ruby-comment"># from Net::HTTP::Proxy()</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_from_env</span> = <span class="ruby-ivar">@proxy_from_env</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span>  = <span class="ruby-ivar">@proxy_address</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_port</span>     = <span class="ruby-ivar">@proxy_port</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_user</span>     = <span class="ruby-ivar">@proxy_user</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_pass</span>     = <span class="ruby-ivar">@proxy_pass</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">p_addr</span> <span class="ruby-operator">==</span> <span class="ruby-value">:ENV</span> <span class="ruby-keyword">then</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_from_env</span> = <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">p_addr</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">p_no_proxy</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">Generic</span>.<span class="ruby-identifier">use_proxy?</span>(<span class="ruby-identifier">p_addr</span>, <span class="ruby-identifier">p_addr</span>, <span class="ruby-identifier">p_port</span>, <span class="ruby-identifier">p_no_proxy</span>)
      <span class="ruby-identifier">p_addr</span> = <span class="ruby-keyword">nil</span>
      <span class="ruby-identifier">p_port</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_address</span> = <span class="ruby-identifier">p_addr</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_port</span>    = <span class="ruby-identifier">p_port</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">default_port</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_user</span>    = <span class="ruby-identifier">p_user</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">proxy_pass</span>    = <span class="ruby-identifier">p_pass</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">http</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HTTP.html#method-c-newobj">newobj</a>
                            </div>

                          </div>

                  <div id="method-c-newobj" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">newobj</span><span
                                class="method-args">(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, p_no_proxy = nil)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HTTP.html#method-c-new">new</a>
                            </div>
                          </div>

                  <div id="method-c-post" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">post</span><span
                                class="method-args">(url, data, header = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Posts data to a host; returns a <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a> object.</p>

<p>Argument <code>url</code> must be a URL; argument <code>data</code> must be a string:</p>

<pre class="ruby"><span class="ruby-identifier">_uri</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">dup</span>
<span class="ruby-identifier">_uri</span>.<span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;/posts&#39;</span>
<span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;{&quot;title&quot;: &quot;foo&quot;, &quot;body&quot;: &quot;bar&quot;, &quot;userId&quot;: 1}&#39;</span>
<span class="ruby-identifier">headers</span> = {<span class="ruby-value">&#39;content-type&#39;:</span> <span class="ruby-string">&#39;application/json&#39;</span>}
<span class="ruby-identifier">res</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">post</span>(<span class="ruby-identifier">_uri</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">headers</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPCreated 201 Created readbody=true&gt;</span>
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>
</pre>

<p>Output:</p>

<pre class="ruby">{
  <span class="ruby-value">&quot;title&quot;:</span> <span class="ruby-string">&quot;foo&quot;</span>,
  <span class="ruby-value">&quot;body&quot;:</span> <span class="ruby-string">&quot;bar&quot;</span>,
  <span class="ruby-value">&quot;userId&quot;:</span> <span class="ruby-value">1</span>,
  <span class="ruby-value">&quot;id&quot;:</span> <span class="ruby-value">101</span>
}
</pre>

<p>Related:</p>
<ul><li>
<p><a href="HTTP/Post.html"><code>Net::HTTP::Post</code></a>: request class for HTTP method <code>POST</code>.</p>
</li><li>
<p><a href="HTTP.html#method-i-post"><code>Net::HTTP#post</code></a>: convenience method for HTTP method <code>POST</code>.</p>
</li></ul>

                              <div class="method-source-code" id="post-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 856</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">post</span>(<span class="ruby-identifier">url</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">header</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">start</span>(<span class="ruby-identifier">url</span>.<span class="ruby-identifier">hostname</span>, <span class="ruby-identifier">url</span>.<span class="ruby-identifier">port</span>,
        <span class="ruby-value">:use_ssl</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">url</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;https&#39;</span> ) {<span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">post</span>(<span class="ruby-identifier">url</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">header</span>)
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-post_form" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">post_form</span><span
                                class="method-args">(url, params)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Posts data to a host; returns a <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a> object.</p>

<p>Argument <code>url</code> must be a URI; argument <code>data</code> must be a hash:</p>

<pre class="ruby"><span class="ruby-identifier">_uri</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">dup</span>
<span class="ruby-identifier">_uri</span>.<span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;/posts&#39;</span>
<span class="ruby-identifier">data</span> = {<span class="ruby-value">title:</span> <span class="ruby-string">&#39;foo&#39;</span>, <span class="ruby-value">body:</span> <span class="ruby-string">&#39;bar&#39;</span>, <span class="ruby-value">userId:</span> <span class="ruby-value">1</span>}
<span class="ruby-identifier">res</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">post_form</span>(<span class="ruby-identifier">_uri</span>, <span class="ruby-identifier">data</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPCreated 201 Created readbody=true&gt;</span>
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>
</pre>

<p>Output:</p>

<pre class="ruby">{
  <span class="ruby-value">&quot;title&quot;:</span> <span class="ruby-string">&quot;foo&quot;</span>,
  <span class="ruby-value">&quot;body&quot;:</span> <span class="ruby-string">&quot;bar&quot;</span>,
  <span class="ruby-value">&quot;userId&quot;:</span> <span class="ruby-string">&quot;1&quot;</span>,
  <span class="ruby-value">&quot;id&quot;:</span> <span class="ruby-value">101</span>
}
</pre>

                              <div class="method-source-code" id="post_form-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 883</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">post_form</span>(<span class="ruby-identifier">url</span>, <span class="ruby-identifier">params</span>)
  <span class="ruby-identifier">req</span> = <span class="ruby-constant">Post</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">url</span>)
  <span class="ruby-identifier">req</span>.<span class="ruby-identifier">form_data</span> = <span class="ruby-identifier">params</span>
  <span class="ruby-identifier">req</span>.<span class="ruby-identifier">basic_auth</span> <span class="ruby-identifier">url</span>.<span class="ruby-identifier">user</span>, <span class="ruby-identifier">url</span>.<span class="ruby-identifier">password</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">url</span>.<span class="ruby-identifier">user</span>
  <span class="ruby-identifier">start</span>(<span class="ruby-identifier">url</span>.<span class="ruby-identifier">hostname</span>, <span class="ruby-identifier">url</span>.<span class="ruby-identifier">port</span>,
        <span class="ruby-value">:use_ssl</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">url</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;https&#39;</span> ) {<span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>)
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-proxy_class-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">proxy_class?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if self is a class which was created by HTTP::Proxy.</p>

                              <div class="method-source-code" id="proxy_class-3F-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1763</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proxy_class?</span>
  <span class="ruby-keyword">defined?</span>(<span class="ruby-ivar">@is_proxy_class</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@is_proxy_class</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-start" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          start(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, opts) &rarr; http
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          start(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_pass = nil, opts) {|http| ... } &rarr; object
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new Net::HTTP object, <code>http</code>, via Net::HTTP.new:</p>
<ul><li>
<p>For arguments <code>address</code> and <code>port</code>, see <a href="HTTP.html#method-c-new"><code>Net::HTTP.new</code></a>.</p>
</li><li>
<p>For proxy-defining arguments <code>p_addr</code> through <code>p_pass</code>, see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>
</li><li>
<p>For argument <code>opts</code>, see below.</p>
</li></ul>

<p>With no block given:</p>
<ul><li>
<p>Calls <code>http.start</code> with no block (see <a href="HTTP.html#method-i-start"><code>start</code></a>), which opens a TCP connection and HTTP session.</p>
</li><li>
<p>Returns <code>http</code>.</p>
</li><li>
<p>The caller should call <a href="HTTP.html#method-i-finish"><code>finish</code></a> to close the session:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">finish</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span> <span class="ruby-comment"># =&gt; false</span>
</pre>
</li></ul>

<p>With a block given:</p>
<ul><li>
<p>Calls <code>http.start</code> with the block (see <a href="HTTP.html#method-i-start"><code>start</code></a>), which:</p>
<ul><li>
<p>Opens a TCP connection and HTTP session.</p>
</li><li>
<p>Calls the block, which may make any number of requests to the host.</p>
</li><li>
<p>Closes the HTTP session and TCP connection on block exit.</p>
</li><li>
<p>Returns the block’s value <code>object</code>.</p>
</li></ul>
</li><li>
<p>Returns <code>object</code>.</p>
</li></ul>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">hostname</span> = <span class="ruby-string">&#39;jsonplaceholder.typicode.com&#39;</span>
<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">hostname</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>).<span class="ruby-identifier">body</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&#39;/todos/2&#39;</span>).<span class="ruby-identifier">body</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Output:</p>

<pre class="ruby">{
  <span class="ruby-value">&quot;userId&quot;:</span> <span class="ruby-value">1</span>,
  <span class="ruby-value">&quot;id&quot;:</span> <span class="ruby-value">1</span>,
  <span class="ruby-value">&quot;title&quot;:</span> <span class="ruby-string">&quot;delectus aut autem&quot;</span>,
  <span class="ruby-value">&quot;completed&quot;:</span> <span class="ruby-keyword">false</span>
}
{
  <span class="ruby-value">&quot;userId&quot;:</span> <span class="ruby-value">1</span>,
  <span class="ruby-value">&quot;id&quot;:</span> <span class="ruby-value">2</span>,
  <span class="ruby-value">&quot;title&quot;:</span> <span class="ruby-string">&quot;quis ut nam facilis et officia qui&quot;</span>,
  <span class="ruby-value">&quot;completed&quot;:</span> <span class="ruby-keyword">false</span>
}
</pre>

<p>If the last argument given is a hash, it is the <code>opts</code> hash, where each key is a method or accessor to be called, and its value is the value to be set.</p>

<p>The keys may include:</p>
<ul><li>
<p><a href="HTTP.html#attribute-i-ca_file"><code>ca_file</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-ca_path"><code>ca_path</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-cert"><code>cert</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-cert_store"><code>cert_store</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-ciphers"><code>ciphers</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-close_on_empty_response"><code>close_on_empty_response</code></a></p>
</li><li>
<p><code>ipaddr</code> (calls <a href="HTTP.html#method-i-ipaddr-3D"><code>ipaddr=</code></a>)</p>
</li><li>
<p><a href="HTTP.html#attribute-i-keep_alive_timeout"><code>keep_alive_timeout</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-key"><code>key</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-open_timeout"><code>open_timeout</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-read_timeout"><code>read_timeout</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-ssl_timeout"><code>ssl_timeout</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-ssl_version"><code>ssl_version</code></a></p>
</li><li>
<p><code>use_ssl</code> (calls <a href="HTTP.html#method-i-use_ssl-3D"><code>use_ssl=</code></a>)</p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_callback"><code>verify_callback</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_depth"><code>verify_depth</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-verify_mode"><code>verify_mode</code></a></p>
</li><li>
<p><a href="HTTP.html#attribute-i-write_timeout"><code>write_timeout</code></a></p>
</li></ul>

<p>Note: If <code>port</code> is <code>nil</code> and <code>opts[:use_ssl]</code> is a truthy value, the value passed to <code>new</code> is <a href="HTTP.html#method-c-https_default_port"><code>Net::HTTP.https_default_port</code></a>, not <code>port</code>.</p>

                              <div class="method-source-code" id="start-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1011</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">start</span>(<span class="ruby-identifier">address</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">arg</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># :yield: +http+</span>
  <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">pop</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">opt</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">try_convert</span>(<span class="ruby-identifier">arg</span>[<span class="ruby-value">-1</span>])
  <span class="ruby-identifier">port</span>, <span class="ruby-identifier">p_addr</span>, <span class="ruby-identifier">p_port</span>, <span class="ruby-identifier">p_user</span>, <span class="ruby-identifier">p_pass</span> = <span class="ruby-operator">*</span><span class="ruby-identifier">arg</span>
  <span class="ruby-identifier">p_addr</span> = <span class="ruby-value">:ENV</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">2</span>
  <span class="ruby-identifier">port</span> = <span class="ruby-identifier">https_default_port</span> <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">port</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">opt</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">opt</span>[<span class="ruby-value">:use_ssl</span>]
  <span class="ruby-identifier">http</span> = <span class="ruby-identifier">new</span>(<span class="ruby-identifier">address</span>, <span class="ruby-identifier">port</span>, <span class="ruby-identifier">p_addr</span>, <span class="ruby-identifier">p_port</span>, <span class="ruby-identifier">p_user</span>, <span class="ruby-identifier">p_pass</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">ipaddr</span> = <span class="ruby-identifier">opt</span>[<span class="ruby-value">:ipaddr</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">opt</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">opt</span>[<span class="ruby-value">:ipaddr</span>]

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">opt</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">opt</span>[<span class="ruby-value">:use_ssl</span>]
      <span class="ruby-identifier">opt</span> = {<span class="ruby-value">verify_mode:</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">VERIFY_PEER</span>}.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">opt</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">http</span>.<span class="ruby-identifier">methods</span>.<span class="ruby-identifier">grep</span>(<span class="ruby-regexp">/\A(\w+)=\z/</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">meth</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">key</span> = <span class="ruby-node">$1</span>.<span class="ruby-identifier">to_sym</span>
      <span class="ruby-identifier">opt</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">key</span>) <span class="ruby-keyword">or</span> <span class="ruby-keyword">next</span>
      <span class="ruby-identifier">http</span>.<span class="ruby-identifier">__send__</span>(<span class="ruby-identifier">meth</span>, <span class="ruby-identifier">opt</span>[<span class="ruby-identifier">key</span>])
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">start</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-version_1_2" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">version_1_2</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code>; retained for compatibility.</p>

                              <div class="method-source-code" id="version_1_2-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 737</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">version_1_2</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-version_1_2-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">version_1_2?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code>; retained for compatibility.</p>

                              <div class="method-source-code" id="version_1_2-3F-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 742</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier ruby-title">version_1_2?</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HTTP.html#method-c-is_version_1_2-3F">is_version_1_2?</a>
                            </div>

                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-active-3F" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">active?</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HTTP.html#method-i-started-3F">started?</a>
                            </div>
                          </div>

                  <div id="method-i-continue_timeout-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">continue_timeout=</span><span
                                class="method-args">(sec)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the continue timeout value, which is the number of seconds to wait for an expected 100 Continue response. If the HTTP object does not receive a response in this many seconds it sends the request body.</p>

                              <div class="method-source-code" id="continue_timeout-3D-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1381</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">continue_timeout=</span>(<span class="ruby-identifier">sec</span>)
  <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">continue_timeout</span> = <span class="ruby-identifier">sec</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@socket</span>
  <span class="ruby-ivar">@continue_timeout</span> = <span class="ruby-identifier">sec</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-copy" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">copy</span><span
                                class="method-args">(path, initheader = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a COPY request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Copy.html"><code>Net::HTTP::Copy</code></a> object created from string <code>path</code> and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">copy</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>)
</pre>

                              <div class="method-source-code" id="copy-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2124</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">copy</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Copy</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>))
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-delete" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">delete</span><span
                                class="method-args">(path, initheader = {&#39;Depth&#39; =&gt; &#39;Infinity&#39;})</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a DELETE request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Delete.html"><code>Net::HTTP::Delete</code></a> object created from string <code>path</code> and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>)
</pre>

                              <div class="method-source-code" id="delete-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2098</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">delete</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span> = {<span class="ruby-string">&#39;Depth&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;Infinity&#39;</span>})
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Delete</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>))
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-finish" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">finish</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Finishes the HTTP session:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">start</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">finish</span>   <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

<p>Raises IOError if not in a session.</p>

                              <div class="method-source-code" id="finish-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1709</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">finish</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">IOError</span>, <span class="ruby-string">&#39;HTTP session not yet started&#39;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">started?</span>
  <span class="ruby-identifier">do_finish</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-get" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          get(path, initheader = nil) {|res| ... }
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a GET request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Get.html"><code>Net::HTTP::Get</code></a> object created from string <code>path</code> and initial headers hash <code>initheader</code>.</p>

<p>With a block given, calls the block with the response body:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>
<span class="ruby-keyword">end</span> <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;{\n  \&quot;userId\&quot;: 1,\n  \&quot;id\&quot;: 1,\n  \&quot;title\&quot;: \&quot;delectus aut autem\&quot;,\n  \&quot;completed\&quot;: false\n}&quot;</span>
</pre>

<p>With no block given, simply returns the response object:</p>

<pre class="ruby"><span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&#39;/&#39;</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
</pre>

<p>Related:</p>
<ul><li>
<p><a href="HTTP/Get.html"><code>Net::HTTP::Get</code></a>: request class for HTTP method GET.</p>
</li><li>
<p><a href="HTTP.html#method-c-get"><code>Net::HTTP.get</code></a>: sends GET request, returns response body.</p>
</li></ul>

                              <div class="method-source-code" id="get-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1915</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">dest</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># :yield: +body_segment+</span>
  <span class="ruby-identifier">res</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>)) {<span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">r</span>.<span class="ruby-identifier">read_body</span> <span class="ruby-identifier">dest</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
    <span class="ruby-identifier">res</span> = <span class="ruby-identifier">r</span>
  }
  <span class="ruby-identifier">res</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-get2" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">get2</span><span
                                class="method-args">(path, initheader = nil)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HTTP.html#method-i-request_get">request_get</a>
                            </div>
                          </div>

                  <div id="method-i-head" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">head</span><span
                                class="method-args">(path, initheader = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a HEAD request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Head.html"><code>Net::HTTP::Head</code></a> object created from string <code>path</code> and initial headers hash <code>initheader</code>:</p>

<pre class="ruby"><span class="ruby-identifier">res</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">head</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
<span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>                    <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">res</span>.<span class="ruby-identifier">to_hash</span>.<span class="ruby-identifier">take</span>(<span class="ruby-value">3</span>)
<span class="ruby-comment"># =&gt;</span>
[[<span class="ruby-string">&quot;date&quot;</span>, [<span class="ruby-string">&quot;Wed, 15 Feb 2023 15:25:42 GMT&quot;</span>]],
 [<span class="ruby-string">&quot;content-type&quot;</span>, [<span class="ruby-string">&quot;application/json; charset=utf-8&quot;</span>]],
 [<span class="ruby-string">&quot;connection&quot;</span>, [<span class="ruby-string">&quot;close&quot;</span>]]]
</pre>

                              <div class="method-source-code" id="head-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1939</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">head</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Head</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>))
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-head2" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">head2</span><span
                                class="method-args">(path, initheader = nil, &amp;block)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HTTP.html#method-i-request_head">request_head</a>
                            </div>
                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">inspect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string representation of <code>self</code>:</p>

<pre class="ruby"><span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>).<span class="ruby-identifier">inspect</span>
<span class="ruby-comment"># =&gt; &quot;#&lt;Net::HTTP jsonplaceholder.typicode.com:80 open=false&gt;&quot;</span>
</pre>

                              <div class="method-source-code" id="inspect-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1136</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">inspect</span>
  <span class="ruby-node">&quot;#&lt;#{self.class} #{@address}:#{@port} open=#{started?}&gt;&quot;</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-ipaddr" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">ipaddr</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the IP address for the connection.</p>

<p>If the session has not been started, returns the value set by <a href="HTTP.html#method-i-ipaddr-3D"><code>ipaddr=</code></a>, or <code>nil</code> if it has not been set:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">ipaddr</span> <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">ipaddr</span> = <span class="ruby-string">&#39;172.67.155.76&#39;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">ipaddr</span> <span class="ruby-comment"># =&gt; &quot;172.67.155.76&quot;</span>
</pre>

<p>If the session has been started, returns the IP address from the socket:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">start</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">ipaddr</span> <span class="ruby-comment"># =&gt; &quot;172.67.155.76&quot;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">finish</span>
</pre>

                              <div class="method-source-code" id="ipaddr-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1275</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">ipaddr</span>
  <span class="ruby-identifier">started?</span> <span class="ruby-operator">?</span>  <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">io</span>.<span class="ruby-identifier">peeraddr</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">:</span> <span class="ruby-ivar">@ipaddr</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-ipaddr-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">ipaddr=</span><span
                                class="method-args">(addr)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the IP address for the connection:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">ipaddr</span> <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">ipaddr</span> = <span class="ruby-string">&#39;172.67.155.76&#39;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">ipaddr</span> <span class="ruby-comment"># =&gt; &quot;172.67.155.76&quot;</span>
</pre>

<p>The IP address may not be set if the session has been started.</p>

                              <div class="method-source-code" id="ipaddr-3D-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1287</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">ipaddr=</span>(<span class="ruby-identifier">addr</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">IOError</span>, <span class="ruby-string">&quot;ipaddr value changed, but session already started&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">started?</span>
  <span class="ruby-ivar">@ipaddr</span> = <span class="ruby-identifier">addr</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-lock" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">lock</span><span
                                class="method-args">(path, body, initheader = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a LOCK request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Lock.html"><code>Net::HTTP::Lock</code></a> object created from string <code>path</code>, string <code>body</code>, and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;{&quot;userId&quot;: 1, &quot;id&quot;: 1, &quot;title&quot;: &quot;delectus aut autem&quot;, &quot;completed&quot;: false}&#39;</span>
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">lock</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>, <span class="ruby-identifier">data</span>)
</pre>

                              <div class="method-source-code" id="lock-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2044</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">lock</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Lock</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>), <span class="ruby-identifier">body</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-max_retries-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">max_retries=</span><span
                                class="method-args">(retries)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the maximum number of times to retry an idempotent request in case of Net::ReadTimeout, IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, OpenSSL::SSL::SSLError, Timeout::Error. The initial value is 1.</p>

<p>Argument <code>retries</code> must be a non-negative numeric value:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">max_retries</span> = <span class="ruby-value">2</span>   <span class="ruby-comment"># =&gt; 2</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">max_retries</span>       <span class="ruby-comment"># =&gt; 2</span>
</pre>

                              <div class="method-source-code" id="max_retries-3D-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1321</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">max_retries=</span>(<span class="ruby-identifier">retries</span>)
  <span class="ruby-identifier">retries</span> = <span class="ruby-identifier">retries</span>.<span class="ruby-identifier">to_int</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">retries</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&#39;max_retries should be non-negative integer number&#39;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@max_retries</span> = <span class="ruby-identifier">retries</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-mkcol" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">mkcol</span><span
                                class="method-args">(path, body = nil, initheader = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a MKCOL request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Mkcol.html"><code>Net::HTTP::Mkcol</code></a> object created from string <code>path</code>, string <code>body</code>, and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;{&quot;userId&quot;: 1, &quot;id&quot;: 1, &quot;title&quot;: &quot;delectus aut autem&quot;, &quot;completed&quot;: false}&#39;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">mkcol</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>, <span class="ruby-identifier">data</span>)
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
</pre>

                              <div class="method-source-code" id="mkcol-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2138</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mkcol</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Mkcol</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>), <span class="ruby-identifier">body</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-move" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">move</span><span
                                class="method-args">(path, initheader = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a MOVE request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Move.html"><code>Net::HTTP::Move</code></a> object created from string <code>path</code> and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">move</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>)
</pre>

                              <div class="method-source-code" id="move-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2111</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">move</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Move</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>))
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-options" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">options</span><span
                                class="method-args">(path, initheader = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends an <a href="HTTP/Options.html"><code>Options</code></a> request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Options.html"><code>Net::HTTP::Options</code></a> object created from string <code>path</code> and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">options</span>(<span class="ruby-string">&#39;/&#39;</span>)
</pre>

                              <div class="method-source-code" id="options-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2071</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">options</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Options</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>))
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-patch" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          patch(path, data, initheader = nil) {|res| ... }
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a PATCH request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Patch.html"><code>Net::HTTP::Patch</code></a> object created from string <code>path</code>, string <code>data</code>, and initial headers hash <code>initheader</code>.</p>

<p>With a block given, calls the block with the response body:</p>

<pre class="ruby"><span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;{&quot;userId&quot;: 1, &quot;id&quot;: 1, &quot;title&quot;: &quot;delectus aut autem&quot;, &quot;completed&quot;: false}&#39;</span>
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">patch</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>, <span class="ruby-identifier">data</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>
<span class="ruby-keyword">end</span> <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;{\n  \&quot;userId\&quot;: 1,\n  \&quot;id\&quot;: 1,\n  \&quot;title\&quot;: \&quot;delectus aut autem\&quot;,\n  \&quot;completed\&quot;: false,\n  \&quot;{\\\&quot;userId\\\&quot;: 1, \\\&quot;id\\\&quot;: 1, \\\&quot;title\\\&quot;: \\\&quot;delectus aut autem\\\&quot;, \\\&quot;completed\\\&quot;: false}\&quot;: \&quot;\&quot;\n}&quot;</span>
</pre>

<p>With no block given, simply returns the response object:</p>

<pre class="ruby"><span class="ruby-identifier">http</span>.<span class="ruby-identifier">patch</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>, <span class="ruby-identifier">data</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPCreated 201 Created readbody=true&gt;</span>
</pre>

                              <div class="method-source-code" id="patch-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2002</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">patch</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">dest</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># :yield: +body_segment+</span>
  <span class="ruby-identifier">send_entity</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">initheader</span>, <span class="ruby-identifier">dest</span>, <span class="ruby-constant">Patch</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-peer_cert" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">peer_cert</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the X509 certificate chain (an array of strings) for the session’s socket peer, or <code>nil</code> if none.</p>

                              <div class="method-source-code" id="peer_cert-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1538</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">peer_cert</span>
  <span class="ruby-keyword">if</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">use_ssl?</span> <span class="ruby-keyword">or</span> <span class="ruby-keyword">not</span> <span class="ruby-ivar">@socket</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">io</span>.<span class="ruby-identifier">peer_cert</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-post" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          post(path, data, initheader = nil) {|res| ... }
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a POST request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Post.html"><code>Net::HTTP::Post</code></a> object created from string <code>path</code>, string <code>data</code>, and initial headers hash <code>initheader</code>.</p>

<p>With a block given, calls the block with the response body:</p>

<pre class="ruby"><span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;{&quot;userId&quot;: 1, &quot;id&quot;: 1, &quot;title&quot;: &quot;delectus aut autem&quot;, &quot;completed&quot;: false}&#39;</span>
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">post</span>(<span class="ruby-string">&#39;/todos&#39;</span>, <span class="ruby-identifier">data</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>
<span class="ruby-keyword">end</span> <span class="ruby-comment"># =&gt; #&lt;Net::HTTPCreated 201 Created readbody=true&gt;</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;{\n  \&quot;{\\\&quot;userId\\\&quot;: 1, \\\&quot;id\\\&quot;: 1, \\\&quot;title\\\&quot;: \\\&quot;delectus aut autem\\\&quot;, \\\&quot;completed\\\&quot;: false}\&quot;: \&quot;\&quot;,\n  \&quot;id\&quot;: 201\n}&quot;</span>
</pre>

<p>With no block given, simply returns the response object:</p>

<pre class="ruby"><span class="ruby-identifier">http</span>.<span class="ruby-identifier">post</span>(<span class="ruby-string">&#39;/todos&#39;</span>, <span class="ruby-identifier">data</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPCreated 201 Created readbody=true&gt;</span>
</pre>

<p>Related:</p>
<ul><li>
<p><a href="HTTP/Post.html"><code>Net::HTTP::Post</code></a>: request class for HTTP method POST.</p>
</li><li>
<p><a href="HTTP.html#method-c-post"><code>Net::HTTP.post</code></a>: sends POST request, returns response body.</p>
</li></ul>

                              <div class="method-source-code" id="post-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1973</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">post</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">dest</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># :yield: +body_segment+</span>
  <span class="ruby-identifier">send_entity</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">initheader</span>, <span class="ruby-identifier">dest</span>, <span class="ruby-constant">Post</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-post2" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">post2</span><span
                                class="method-args">(path, data, initheader = nil)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HTTP.html#method-i-request_post">request_post</a>
                            </div>
                          </div>

                  <div id="method-i-propfind" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">propfind</span><span
                                class="method-args">(path, body = nil, initheader = {&#39;Depth&#39; =&gt; &#39;0&#39;})</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a PROPFIND request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Propfind.html"><code>Net::HTTP::Propfind</code></a> object created from string <code>path</code>, string <code>body</code>, and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;{&quot;userId&quot;: 1, &quot;id&quot;: 1, &quot;title&quot;: &quot;delectus aut autem&quot;, &quot;completed&quot;: false}&#39;</span>
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">propfind</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>, <span class="ruby-identifier">data</span>)
</pre>

                              <div class="method-source-code" id="propfind-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2085</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">propfind</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">initheader</span> = {<span class="ruby-string">&#39;Depth&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;0&#39;</span>})
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Propfind</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>), <span class="ruby-identifier">body</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-proppatch" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">proppatch</span><span
                                class="method-args">(path, body, initheader = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a PROPPATCH request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Proppatch.html"><code>Net::HTTP::Proppatch</code></a> object created from string <code>path</code>, string <code>body</code>, and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;{&quot;userId&quot;: 1, &quot;id&quot;: 1, &quot;title&quot;: &quot;delectus aut autem&quot;, &quot;completed&quot;: false}&#39;</span>
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">proppatch</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>, <span class="ruby-identifier">data</span>)
</pre>

                              <div class="method-source-code" id="proppatch-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2030</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proppatch</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Proppatch</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>), <span class="ruby-identifier">body</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-proxy-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">proxy?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if a proxy server is defined, <code>false</code> otherwise; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>

                              <div class="method-source-code" id="proxy-3F-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1786</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proxy?</span>
  <span class="ruby-operator">!</span><span class="ruby-operator">!</span>(<span class="ruby-ivar">@proxy_from_env</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">proxy_uri</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@proxy_address</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-proxy_address" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">proxy_address</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the address of the proxy server, if defined, <code>nil</code> otherwise; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>

                              <div class="method-source-code" id="proxy_address-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1808</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proxy_address</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@proxy_from_env</span> <span class="ruby-keyword">then</span>
    <span class="ruby-identifier">proxy_uri</span>&amp;.<span class="ruby-identifier">hostname</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@proxy_address</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HTTP.html#method-i-proxyaddr">proxyaddr</a>
                            </div>

                          </div>

                  <div id="method-i-proxy_from_env-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">proxy_from_env?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the proxy server is defined in the environment, <code>false</code> otherwise; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>

                              <div class="method-source-code" id="proxy_from_env-3F-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1793</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proxy_from_env?</span>
  <span class="ruby-ivar">@proxy_from_env</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-proxy_pass" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">proxy_pass</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the password of the proxy server, if defined, <code>nil</code> otherwise; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>

                              <div class="method-source-code" id="proxy_pass-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1839</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proxy_pass</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@proxy_from_env</span>
    <span class="ruby-identifier">pass</span> = <span class="ruby-identifier">proxy_uri</span>&amp;.<span class="ruby-identifier">password</span>
    <span class="ruby-identifier">unescape</span>(<span class="ruby-identifier">pass</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">pass</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@proxy_pass</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-proxy_port" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">proxy_port</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the port number of the proxy server, if defined, <code>nil</code> otherwise; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>

                              <div class="method-source-code" id="proxy_port-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1818</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proxy_port</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@proxy_from_env</span> <span class="ruby-keyword">then</span>
    <span class="ruby-identifier">proxy_uri</span>&amp;.<span class="ruby-identifier">port</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@proxy_port</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HTTP.html#method-i-proxyport">proxyport</a>
                            </div>

                          </div>

                  <div id="method-i-proxy_user" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">proxy_user</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the user name of the proxy server, if defined, <code>nil</code> otherwise; see <a href="HTTP.html#class-Net::HTTP-label-Proxy+Server">Proxy Server</a>.</p>

                              <div class="method-source-code" id="proxy_user-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1828</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proxy_user</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@proxy_from_env</span>
    <span class="ruby-identifier">user</span> = <span class="ruby-identifier">proxy_uri</span>&amp;.<span class="ruby-identifier">user</span>
    <span class="ruby-identifier">unescape</span>(<span class="ruby-identifier">user</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">user</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@proxy_user</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-proxyaddr" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">proxyaddr</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HTTP.html#method-i-proxy_address">proxy_address</a>
                            </div>
                          </div>

                  <div id="method-i-proxyport" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">proxyport</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HTTP.html#method-i-proxy_port">proxy_port</a>
                            </div>
                          </div>

                  <div id="method-i-put" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">put</span><span
                                class="method-args">(path, data, initheader = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a PUT request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Put.html"><code>Net::HTTP::Put</code></a> object created from string <code>path</code>, string <code>data</code>, and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;{&quot;userId&quot;: 1, &quot;id&quot;: 1, &quot;title&quot;: &quot;delectus aut autem&quot;, &quot;completed&quot;: false}&#39;</span>
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">put</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>, <span class="ruby-identifier">data</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
</pre>

                              <div class="method-source-code" id="put-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2016</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">put</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Put</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>), <span class="ruby-identifier">data</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-read_timeout-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">read_timeout=</span><span
                                class="method-args">(sec)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the read timeout, in seconds, for <code>self</code> to integer <code>sec</code>; the initial value is 60.</p>

<p>Argument <code>sec</code> must be a non-negative numeric value:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">read_timeout</span> <span class="ruby-comment"># =&gt; 60</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">read_timeout</span> = <span class="ruby-value">0</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>) <span class="ruby-comment"># Raises Net::ReadTimeout.</span>
</pre>

                              <div class="method-source-code" id="read_timeout-3D-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1344</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">read_timeout=</span>(<span class="ruby-identifier">sec</span>)
  <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">read_timeout</span> = <span class="ruby-identifier">sec</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@socket</span>
  <span class="ruby-ivar">@read_timeout</span> = <span class="ruby-identifier">sec</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-request" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">request</span><span
                                class="method-args">(req, body = nil) { |response| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends the given request <code>req</code> to the server; forms the response into a <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a> object.</p>

<p>The given <code>req</code> must be an instance of a <a href="HTTPRequest.html#class-Net::HTTPRequest-label-Request+Subclasses">subclass of Net::HTTPRequest</a>. Argument <code>body</code> should be given only if needed for the request.</p>

<p>With no block given, returns the response object:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)

<span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>

<span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Post</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;/todos&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>, <span class="ruby-string">&#39;xyzzy&#39;</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTPCreated 201 Created readbody=true&gt;</span>
</pre>

<p>With a block given, calls the block with the response and returns the response:</p>

<pre class="ruby"><span class="ruby-identifier">req</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>
<span class="ruby-keyword">end</span> <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-comment">#&lt;Net::HTTPOK 200 OK readbody=false&gt;</span>
</pre>

                              <div class="method-source-code" id="request-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2296</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">request</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">body</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)  <span class="ruby-comment"># :yield: +response+</span>
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">started?</span>
    <span class="ruby-identifier">start</span> {
      <span class="ruby-identifier">req</span>[<span class="ruby-string">&#39;connection&#39;</span>] <span class="ruby-operator">||=</span> <span class="ruby-string">&#39;close&#39;</span>
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">request</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">body</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
    }
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">proxy_user</span>()
    <span class="ruby-identifier">req</span>.<span class="ruby-identifier">proxy_basic_auth</span> <span class="ruby-identifier">proxy_user</span>(), <span class="ruby-identifier">proxy_pass</span>() <span class="ruby-keyword">unless</span> <span class="ruby-identifier">use_ssl?</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">req</span>.<span class="ruby-identifier">set_body_internal</span> <span class="ruby-identifier">body</span>
  <span class="ruby-identifier">res</span> = <span class="ruby-identifier">transport_request</span>(<span class="ruby-identifier">req</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">sspi_auth?</span>(<span class="ruby-identifier">res</span>)
    <span class="ruby-identifier">sspi_auth</span>(<span class="ruby-identifier">req</span>)
    <span class="ruby-identifier">res</span> = <span class="ruby-identifier">transport_request</span>(<span class="ruby-identifier">req</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">res</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-request_get" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">request_get</span><span
                                class="method-args">(path, initheader = nil) { |response| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a GET request to the server; forms the response into a <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a> object.</p>

<p>The request is based on the <a href="HTTP/Get.html"><code>Net::HTTP::Get</code></a> object created from string <code>path</code> and initial headers hash <code>initheader</code>.</p>

<p>With no block given, returns the response object:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">request_get</span>(<span class="ruby-string">&#39;/todos&#39;</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
</pre>

<p>With a block given, calls the block with the response object and returns the response object:</p>

<pre class="ruby"><span class="ruby-identifier">http</span>.<span class="ruby-identifier">request_get</span>(<span class="ruby-string">&#39;/todos&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>
<span class="ruby-keyword">end</span> <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-comment">#&lt;Net::HTTPOK 200 OK readbody=false&gt;</span>
</pre>

                              <div class="method-source-code" id="request_get-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2177</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">request_get</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># :yield: +response+</span>
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Get</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>), <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HTTP.html#method-i-get2">get2</a>
                            </div>

                          </div>

                  <div id="method-i-request_head" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">request_head</span><span
                                class="method-args">(path, initheader = nil, &amp;block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a HEAD request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Head.html"><code>Net::HTTP::Head</code></a> object created from string <code>path</code> and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">head</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>) <span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
</pre>

                              <div class="method-source-code" id="request_head-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2190</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">request_head</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Head</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>), <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HTTP.html#method-i-head2">head2</a>
                            </div>

                          </div>

                  <div id="method-i-request_post" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">request_post</span><span
                                class="method-args">(path, data, initheader = nil) { |response| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a POST request to the server; forms the response into a <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a> object.</p>

<p>The request is based on the <a href="HTTP/Post.html"><code>Net::HTTP::Post</code></a> object created from string <code>path</code>, string <code>data</code>, and initial headers hash <code>initheader</code>.</p>

<p>With no block given, returns the response object:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">post</span>(<span class="ruby-string">&#39;/todos&#39;</span>, <span class="ruby-string">&#39;xyzzy&#39;</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTPCreated 201 Created readbody=true&gt;</span>
</pre>

<p>With a block given, calls the block with the response body and returns the response object:</p>

<pre class="ruby"><span class="ruby-identifier">http</span>.<span class="ruby-identifier">post</span>(<span class="ruby-string">&#39;/todos&#39;</span>, <span class="ruby-string">&#39;xyzzy&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">res</span>
<span class="ruby-keyword">end</span> <span class="ruby-comment"># =&gt; #&lt;Net::HTTPCreated 201 Created readbody=true&gt;</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;{\n  \&quot;xyzzy\&quot;: \&quot;\&quot;,\n  \&quot;id\&quot;: 201\n}&quot;</span>
</pre>

                              <div class="method-source-code" id="request_post-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2217</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">request_post</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-comment"># :yield: +response+</span>
  <span class="ruby-identifier">request</span> <span class="ruby-constant">Post</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>), <span class="ruby-identifier">data</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HTTP.html#method-i-post2">post2</a>
                            </div>

                          </div>

                  <div id="method-i-response_body_encoding-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">response_body_encoding=</span><span
                                class="method-args">(value)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the encoding to be used for the response body; returns the encoding.</p>

<p>The given <code>value</code> may be:</p>
<ul><li>
<p>An Encoding object.</p>
</li><li>
<p>The name of an encoding.</p>
</li><li>
<p>An alias for an encoding name.</p>
</li></ul>

<p>See Encoding.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">response_body_encoding</span> = <span class="ruby-constant">Encoding</span><span class="ruby-operator">::</span><span class="ruby-constant">US_ASCII</span> <span class="ruby-comment"># =&gt; #&lt;Encoding:US-ASCII&gt;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">response_body_encoding</span> = <span class="ruby-string">&#39;US-ASCII&#39;</span>         <span class="ruby-comment"># =&gt; &quot;US-ASCII&quot;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">response_body_encoding</span> = <span class="ruby-string">&#39;ASCII&#39;</span>            <span class="ruby-comment"># =&gt; &quot;ASCII&quot;</span>
</pre>

                              <div class="method-source-code" id="response_body_encoding-3D-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1230</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">response_body_encoding=</span>(<span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">value</span> = <span class="ruby-constant">Encoding</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">value</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
  <span class="ruby-ivar">@response_body_encoding</span> = <span class="ruby-identifier">value</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-send_request" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">send_request</span><span
                                class="method-args">(name, path, data = nil, header = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends an HTTP request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTPRequest.html"><code>Net::HTTPRequest</code></a> object created from string <code>path</code>, string <code>data</code>, and initial headers hash <code>header</code>. That object is an instance of the <a href="HTTPRequest.html#class-Net::HTTPRequest-label-Request+Subclasses">subclass of Net::HTTPRequest</a>, that corresponds to the given uppercase string <code>name</code>, which must be an <a href="https://en.wikipedia.org/wiki/HTTP#Request_methods">HTTP request method</a> or a <a href="https://en.wikipedia.org/wiki/WebDAV#Implementation">WebDAV request method</a>.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">send_request</span>(<span class="ruby-string">&#39;GET&#39;</span>, <span class="ruby-string">&#39;/todos/1&#39;</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTPOK 200 OK readbody=true&gt;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">send_request</span>(<span class="ruby-string">&#39;POST&#39;</span>, <span class="ruby-string">&#39;/todos&#39;</span>, <span class="ruby-string">&#39;xyzzy&#39;</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTPCreated 201 Created readbody=true&gt;</span>
</pre>

                              <div class="method-source-code" id="send_request-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2260</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">send_request</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">data</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">header</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">has_response_body</span> = <span class="ruby-identifier">name</span> <span class="ruby-operator">!=</span> <span class="ruby-string">&#39;HEAD&#39;</span>
  <span class="ruby-identifier">r</span> = <span class="ruby-constant">HTTPGenericRequest</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>,(<span class="ruby-identifier">data</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>),<span class="ruby-identifier">has_response_body</span>,<span class="ruby-identifier">path</span>,<span class="ruby-identifier">header</span>)
  <span class="ruby-identifier">request</span> <span class="ruby-identifier">r</span>, <span class="ruby-identifier">data</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-set_debug_output" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">set_debug_output</span><span
                                class="method-args">(output)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><strong>WARNING</strong> This method opens a serious security hole. Never use this method in production code.</p>

<p>Sets the output stream for debugging:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-string">&#39;w&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">set_debug_output</span>(<span class="ruby-identifier">file</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">start</span>
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">get</span>(<span class="ruby-string">&#39;/nosuch/1&#39;</span>)
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">finish</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">puts</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>)
</pre>

<p>Output:</p>

<pre>opening connection to jsonplaceholder.typicode.com:80...
opened
&lt;- &quot;GET /nosuch/1 HTTP/1.1\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: Ruby\r\nHost: jsonplaceholder.typicode.com\r\n\r\n&quot;
-&gt; &quot;HTTP/1.1 404 Not Found\r\n&quot;
-&gt; &quot;Date: Mon, 12 Dec 2022 21:14:11 GMT\r\n&quot;
-&gt; &quot;Content-Type: application/json; charset=utf-8\r\n&quot;
-&gt; &quot;Content-Length: 2\r\n&quot;
-&gt; &quot;Connection: keep-alive\r\n&quot;
-&gt; &quot;X-Powered-By: Express\r\n&quot;
-&gt; &quot;X-Ratelimit-Limit: 1000\r\n&quot;
-&gt; &quot;X-Ratelimit-Remaining: 999\r\n&quot;
-&gt; &quot;X-Ratelimit-Reset: 1670879660\r\n&quot;
-&gt; &quot;Vary: Origin, Accept-Encoding\r\n&quot;
-&gt; &quot;Access-Control-Allow-Credentials: true\r\n&quot;
-&gt; &quot;Cache-Control: max-age=43200\r\n&quot;
-&gt; &quot;Pragma: no-cache\r\n&quot;
-&gt; &quot;Expires: -1\r\n&quot;
-&gt; &quot;X-Content-Type-Options: nosniff\r\n&quot;
-&gt; &quot;Etag: W/\&quot;2-vyGp6PvFo4RvsFtPoIWeCReyIC8\&quot;\r\n&quot;
-&gt; &quot;Via: 1.1 vegur\r\n&quot;
-&gt; &quot;CF-Cache-Status: MISS\r\n&quot;
-&gt; &quot;Server-Timing: cf-q-config;dur=1.3000000762986e-05\r\n&quot;
-&gt; &quot;Report-To: {\&quot;endpoints\&quot;:[{\&quot;url\&quot;:\&quot;https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=yOr40jo%2BwS1KHzhTlVpl54beJ5Wx2FcG4gGV0XVrh3X9OlR5q4drUn2dkt5DGO4GDcE%2BVXT7CNgJvGs%2BZleIyMu8CLieFiDIvOviOY3EhHg94m0ZNZgrEdpKD0S85S507l1vsEwEHkoTm%2Ff19SiO\&quot;}],\&quot;group\&quot;:\&quot;cf-nel\&quot;,\&quot;max_age\&quot;:604800}\r\n&quot;
-&gt; &quot;NEL: {\&quot;success_fraction\&quot;:0,\&quot;report_to\&quot;:\&quot;cf-nel\&quot;,\&quot;max_age\&quot;:604800}\r\n&quot;
-&gt; &quot;Server: cloudflare\r\n&quot;
-&gt; &quot;CF-RAY: 778977dc484ce591-DFW\r\n&quot;
-&gt; &quot;alt-svc: h3=\&quot;:443\&quot;; ma=86400, h3-29=\&quot;:443\&quot;; ma=86400\r\n&quot;
-&gt; &quot;\r\n&quot;
reading 2 bytes...
-&gt; &quot;{}&quot;
read 2 bytes
Conn keep-alive</pre>

                              <div class="method-source-code" id="set_debug_output-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1189</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_debug_output</span>(<span class="ruby-identifier">output</span>)
  <span class="ruby-identifier">warn</span> <span class="ruby-string">&#39;Net::HTTP#set_debug_output called after HTTP started&#39;</span>, <span class="ruby-value">uplevel:</span> <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">started?</span>
  <span class="ruby-ivar">@debug_output</span> = <span class="ruby-identifier">output</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-start" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">start</span><span
                                class="method-args">() { |http| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Starts an HTTP session.</p>

<p>Without a block, returns <code>self</code>:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTP jsonplaceholder.typicode.com:80 open=false&gt;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">start</span>
<span class="ruby-comment"># =&gt; #&lt;Net::HTTP jsonplaceholder.typicode.com:80 open=true&gt;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">finish</span>
</pre>

<p>With a block, calls the block with <code>self</code>, finishes the session when the block exits, and returns the block’s value:</p>

<pre class="ruby"><span class="ruby-identifier">http</span>.<span class="ruby-identifier">start</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">http</span>
<span class="ruby-keyword">end</span>
<span class="ruby-comment"># =&gt; #&lt;Net::HTTP jsonplaceholder.typicode.com:80 open=false&gt;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="start-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1566</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">start</span>  <span class="ruby-comment"># :yield: http</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">IOError</span>, <span class="ruby-string">&#39;HTTP session already opened&#39;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@started</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
    <span class="ruby-keyword">begin</span>
      <span class="ruby-identifier">do_start</span>
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">yield</span>(<span class="ruby-keyword">self</span>)
    <span class="ruby-keyword">ensure</span>
      <span class="ruby-identifier">do_finish</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">do_start</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-started-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">started?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the HTTP session has been started:</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span> <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">start</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">finish</span> <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span> <span class="ruby-comment"># =&gt; false</span>

<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">start</span>(<span class="ruby-identifier">hostname</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">http</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span>
<span class="ruby-keyword">end</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">started?</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="started-3F-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1414</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">started?</span>
  <span class="ruby-ivar">@started</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HTTP.html#method-i-active-3F">active?</a>
                            </div>

                          </div>

                  <div id="method-i-trace" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">trace</span><span
                                class="method-args">(path, initheader = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends a TRACE request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Trace.html"><code>Net::HTTP::Trace</code></a> object created from string <code>path</code> and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">trace</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>)
</pre>

                              <div class="method-source-code" id="trace-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2151</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">trace</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Trace</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>))
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-unlock" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">unlock</span><span
                                class="method-args">(path, body, initheader = nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sends an UNLOCK request to the server; returns an instance of a subclass of <a href="HTTPResponse.html"><code>Net::HTTPResponse</code></a>.</p>

<p>The request is based on the <a href="HTTP/Unlock.html"><code>Net::HTTP::Unlock</code></a> object created from string <code>path</code>, string <code>body</code>, and initial headers hash <code>initheader</code>.</p>

<pre class="ruby"><span class="ruby-identifier">data</span> = <span class="ruby-string">&#39;{&quot;userId&quot;: 1, &quot;id&quot;: 1, &quot;title&quot;: &quot;delectus aut autem&quot;, &quot;completed&quot;: false}&#39;</span>
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">unlock</span>(<span class="ruby-string">&#39;/todos/1&#39;</span>, <span class="ruby-identifier">data</span>)
</pre>

                              <div class="method-source-code" id="unlock-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2058</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">unlock</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">body</span>, <span class="ruby-identifier">initheader</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">request</span>(<span class="ruby-constant">Unlock</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>), <span class="ruby-identifier">body</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-use_ssl-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">use_ssl=</span><span
                                class="method-args">(flag)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets whether a new session is to use <a href="https://en.wikipedia.org/wiki/Transport_Layer_Security">Transport Layer Security</a>:</p>

<p>Raises IOError if attempting to change during a session.</p>

<p>Raises OpenSSL::SSL::SSLError if the port is not an HTTPS port.</p>

                              <div class="method-source-code" id="use_ssl-3D-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1436</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">use_ssl=</span>(<span class="ruby-identifier">flag</span>)
  <span class="ruby-identifier">flag</span> = <span class="ruby-identifier">flag</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">started?</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@use_ssl</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">flag</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">IOError</span>, <span class="ruby-string">&quot;use_ssl value changed, but session already started&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@use_ssl</span> = <span class="ruby-identifier">flag</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-use_ssl-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">use_ssl?</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>self</code> uses SSL, <code>false</code> otherwise. See <a href="HTTP.html#method-i-use_ssl-3D"><code>Net::HTTP#use_ssl=</code></a>.</p>

                              <div class="method-source-code" id="use_ssl-3F-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1426</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">use_ssl?</span>
  <span class="ruby-ivar">@use_ssl</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-write_timeout-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">write_timeout=</span><span
                                class="method-args">(sec)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the write timeout, in seconds, for <code>self</code> to integer <code>sec</code>; the initial value is 60.</p>

<p>Argument <code>sec</code> must be a non-negative numeric value:</p>

<pre class="ruby"><span class="ruby-identifier">_uri</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">dup</span>
<span class="ruby-identifier">_uri</span>.<span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;/posts&#39;</span>
<span class="ruby-identifier">body</span> = <span class="ruby-string">&#39;bar&#39;</span> <span class="ruby-operator">*</span> <span class="ruby-value">200000</span>
<span class="ruby-identifier">data</span> = <span class="ruby-identifier">&lt;&lt;EOF</span>
<span class="ruby-value">{&quot;title&quot;: &quot;foo&quot;, &quot;body&quot;: &quot;#{body}&quot;, &quot;userId&quot;: &quot;1&quot;}
</span><span class="ruby-identifier">EOF</span>
<span class="ruby-identifier">headers</span> = {<span class="ruby-value">&#39;content-type&#39;:</span> <span class="ruby-string">&#39;application/json&#39;</span>}
<span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hostname</span>)
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">write_timeout</span> <span class="ruby-comment"># =&gt; 60</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">post</span>(<span class="ruby-identifier">_uri</span>.<span class="ruby-identifier">path</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">headers</span>)
<span class="ruby-comment"># =&gt; #&lt;Net::HTTPCreated 201 Created readbody=true&gt;</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">write_timeout</span> = <span class="ruby-value">0</span>
<span class="ruby-identifier">http</span>.<span class="ruby-identifier">post</span>(<span class="ruby-identifier">_uri</span>.<span class="ruby-identifier">path</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">headers</span>) <span class="ruby-comment"># Raises Net::WriteTimeout.</span>
</pre>

                              <div class="method-source-code" id="write_timeout-3D-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1368</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">write_timeout=</span>(<span class="ruby-identifier">sec</span>)
  <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">write_timeout</span> = <span class="ruby-identifier">sec</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@socket</span>
  <span class="ruby-ivar">@write_timeout</span> = <span class="ruby-identifier">sec</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-D" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">D</span><span
                                class="method-args">(msg)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="HTTP.html#method-i-debug">debug</a>
                            </div>
                          </div>

                  <div id="method-i-addr_port" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">addr_port</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>utils</p>

                              <div class="method-source-code" id="addr_port-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2465</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">addr_port</span>
  <span class="ruby-identifier">addr</span> = <span class="ruby-identifier">address</span>
  <span class="ruby-identifier">addr</span> = <span class="ruby-node">&quot;[#{addr}]&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">&quot;:&quot;</span>)
  <span class="ruby-identifier">default_port</span> = <span class="ruby-identifier">use_ssl?</span> <span class="ruby-operator">?</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">https_default_port</span> <span class="ruby-operator">:</span> <span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">http_default_port</span>
  <span class="ruby-identifier">default_port</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">port</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">addr</span> <span class="ruby-operator">:</span> <span class="ruby-node">&quot;#{addr}:#{port}&quot;</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-begin_transport" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">begin_transport</span><span
                                class="method-args">(req)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="begin_transport-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2382</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">begin_transport</span>(<span class="ruby-identifier">req</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">closed?</span>
    <span class="ruby-identifier">connect</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-ivar">@last_communicated</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@last_communicated</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@keep_alive_timeout</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Process</span>.<span class="ruby-identifier">clock_gettime</span>(<span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-constant">CLOCK_MONOTONIC</span>)
      <span class="ruby-identifier">debug</span> <span class="ruby-string">&#39;Conn close because of keep_alive_timeout&#39;</span>
      <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span>
      <span class="ruby-identifier">connect</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">io</span>.<span class="ruby-identifier">to_io</span>.<span class="ruby-identifier">wait_readable</span>(<span class="ruby-value">0</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">eof?</span>
      <span class="ruby-identifier">debug</span> <span class="ruby-string">&quot;Conn close because of EOF&quot;</span>
      <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span>
      <span class="ruby-identifier">connect</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">req</span>.<span class="ruby-identifier">response_body_permitted?</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@close_on_empty_response</span>
    <span class="ruby-identifier">req</span>[<span class="ruby-string">&#39;connection&#39;</span>] <span class="ruby-operator">||=</span> <span class="ruby-string">&#39;close&#39;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">req</span>.<span class="ruby-identifier">update_uri</span> <span class="ruby-identifier">address</span>, <span class="ruby-identifier">port</span>, <span class="ruby-identifier">use_ssl?</span>
  <span class="ruby-identifier">req</span>[<span class="ruby-string">&#39;host&#39;</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">addr_port</span>()
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-connect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">connect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="connect-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1586</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">connect</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">use_ssl?</span>
    <span class="ruby-comment"># reference early to load OpenSSL before connecting,</span>
    <span class="ruby-comment"># as OpenSSL may take time to load.</span>
    <span class="ruby-ivar">@ssl_context</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSLContext</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">proxy?</span> <span class="ruby-keyword">then</span>
    <span class="ruby-identifier">conn_addr</span> = <span class="ruby-identifier">proxy_address</span>
    <span class="ruby-identifier">conn_port</span> = <span class="ruby-identifier">proxy_port</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">conn_addr</span> = <span class="ruby-identifier">conn_address</span>
    <span class="ruby-identifier">conn_port</span> = <span class="ruby-identifier">port</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;opening connection to #{conn_addr}:#{conn_port}...&quot;</span>
  <span class="ruby-identifier">s</span> = <span class="ruby-constant">Timeout</span>.<span class="ruby-identifier">timeout</span>(<span class="ruby-ivar">@open_timeout</span>, <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">OpenTimeout</span>) {
    <span class="ruby-keyword">begin</span>
      <span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">conn_addr</span>, <span class="ruby-identifier">conn_port</span>, <span class="ruby-ivar">@local_host</span>, <span class="ruby-ivar">@local_port</span>)
    <span class="ruby-keyword">rescue</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">e</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>, <span class="ruby-string">&quot;Failed to open TCP connection to &quot;</span> <span class="ruby-operator">+</span>
        <span class="ruby-node">&quot;#{conn_addr}:#{conn_port} (#{e.message})&quot;</span>
    <span class="ruby-keyword">end</span>
  }
  <span class="ruby-identifier">s</span>.<span class="ruby-identifier">setsockopt</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">IPPROTO_TCP</span>, <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">TCP_NODELAY</span>, <span class="ruby-value">1</span>)
  <span class="ruby-identifier">debug</span> <span class="ruby-string">&quot;opened&quot;</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">use_ssl?</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">proxy?</span>
      <span class="ruby-identifier">plain_sock</span> = <span class="ruby-constant">BufferedIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">s</span>, <span class="ruby-value">read_timeout:</span> <span class="ruby-ivar">@read_timeout</span>,
                                  <span class="ruby-value">write_timeout:</span> <span class="ruby-ivar">@write_timeout</span>,
                                  <span class="ruby-value">continue_timeout:</span> <span class="ruby-ivar">@continue_timeout</span>,
                                  <span class="ruby-value">debug_output:</span> <span class="ruby-ivar">@debug_output</span>)
      <span class="ruby-identifier">buf</span> = <span class="ruby-node">+&quot;CONNECT #{conn_address}:#{@port} HTTP/#{HTTPVersion}\r\n&quot;</span> \
        <span class="ruby-node">&quot;Host: #{@address}:#{@port}\r\n&quot;</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">proxy_user</span>
        <span class="ruby-identifier">credential</span> = [<span class="ruby-node">&quot;#{proxy_user}:#{proxy_pass}&quot;</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-string">&#39;m0&#39;</span>)
        <span class="ruby-identifier">buf</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;Proxy-Authorization: Basic #{credential}\r\n&quot;</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-identifier">buf</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\r\n&quot;</span>
      <span class="ruby-identifier">plain_sock</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">buf</span>)
      <span class="ruby-constant">HTTPResponse</span>.<span class="ruby-identifier">read_new</span>(<span class="ruby-identifier">plain_sock</span>).<span class="ruby-identifier">value</span>
      <span class="ruby-comment"># assuming nothing left in buffers after successful CONNECT response</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">ssl_parameters</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
    <span class="ruby-identifier">iv_list</span> = <span class="ruby-identifier">instance_variables</span>
    <span class="ruby-constant">SSL_IVNAMES</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ivname</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">iv_list</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">ivname</span>)
        <span class="ruby-identifier">value</span> = <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">ivname</span>)
        <span class="ruby-keyword">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
          <span class="ruby-identifier">ssl_parameters</span>[<span class="ruby-constant">SSL_ATTRIBUTES</span>[<span class="ruby-identifier">i</span>]] = <span class="ruby-identifier">value</span>
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@ssl_context</span>.<span class="ruby-identifier">set_params</span>(<span class="ruby-identifier">ssl_parameters</span>)
    <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@ssl_context</span>.<span class="ruby-identifier">session_cache_mode</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-comment"># a dummy method on JRuby</span>
      <span class="ruby-ivar">@ssl_context</span>.<span class="ruby-identifier">session_cache_mode</span> =
          <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSLContext</span><span class="ruby-operator">::</span><span class="ruby-constant">SESSION_CACHE_CLIENT</span> <span class="ruby-operator">|</span>
              <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSLContext</span><span class="ruby-operator">::</span><span class="ruby-constant">SESSION_CACHE_NO_INTERNAL_STORE</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@ssl_context</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:session_new_cb</span>) <span class="ruby-comment"># not implemented under JRuby</span>
      <span class="ruby-ivar">@ssl_context</span>.<span class="ruby-identifier">session_new_cb</span> = <span class="ruby-identifier">proc</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">sock</span>, <span class="ruby-identifier">sess</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@ssl_session</span> = <span class="ruby-identifier">sess</span> }
    <span class="ruby-keyword">end</span>

    <span class="ruby-comment"># Still do the post_connection_check below even if connecting</span>
    <span class="ruby-comment"># to IP address</span>
    <span class="ruby-identifier">verify_hostname</span> = <span class="ruby-ivar">@ssl_context</span>.<span class="ruby-identifier">verify_hostname</span>

    <span class="ruby-comment"># Server Name Indication (SNI) RFC 3546/6066</span>
    <span class="ruby-keyword">case</span> <span class="ruby-ivar">@address</span>
    <span class="ruby-keyword">when</span> <span class="ruby-constant">Resolv</span><span class="ruby-operator">::</span><span class="ruby-constant">IPv4</span><span class="ruby-operator">::</span><span class="ruby-constant">Regex</span>, <span class="ruby-constant">Resolv</span><span class="ruby-operator">::</span><span class="ruby-constant">IPv6</span><span class="ruby-operator">::</span><span class="ruby-constant">Regex</span>
      <span class="ruby-comment"># don&#39;t set SNI, as IP addresses in SNI is not valid</span>
      <span class="ruby-comment"># per RFC 6066, section 3.</span>

      <span class="ruby-comment"># Avoid openssl warning</span>
      <span class="ruby-ivar">@ssl_context</span>.<span class="ruby-identifier">verify_hostname</span> = <span class="ruby-keyword">false</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">ssl_host_address</span> = <span class="ruby-ivar">@address</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;starting SSL for #{conn_addr}:#{conn_port}...&quot;</span>
    <span class="ruby-identifier">s</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSLSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">s</span>, <span class="ruby-ivar">@ssl_context</span>)
    <span class="ruby-identifier">s</span>.<span class="ruby-identifier">sync_close</span> = <span class="ruby-keyword">true</span>
    <span class="ruby-identifier">s</span>.<span class="ruby-identifier">hostname</span> = <span class="ruby-identifier">ssl_host_address</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:hostname=</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">ssl_host_address</span>

    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@ssl_session</span> <span class="ruby-keyword">and</span>
       <span class="ruby-constant">Process</span>.<span class="ruby-identifier">clock_gettime</span>(<span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-constant">CLOCK_REALTIME</span>) <span class="ruby-operator">&lt;</span> <span class="ruby-ivar">@ssl_session</span>.<span class="ruby-identifier">time</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@ssl_session</span>.<span class="ruby-identifier">timeout</span>
      <span class="ruby-identifier">s</span>.<span class="ruby-identifier">session</span> = <span class="ruby-ivar">@ssl_session</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">ssl_socket_connect</span>(<span class="ruby-identifier">s</span>, <span class="ruby-ivar">@open_timeout</span>)
    <span class="ruby-keyword">if</span> (<span class="ruby-ivar">@ssl_context</span>.<span class="ruby-identifier">verify_mode</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">VERIFY_NONE</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">verify_hostname</span>
      <span class="ruby-identifier">s</span>.<span class="ruby-identifier">post_connection_check</span>(<span class="ruby-ivar">@address</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;SSL established, protocol: #{s.ssl_version}, cipher: #{s.cipher[0]}&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@socket</span> = <span class="ruby-constant">BufferedIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">s</span>, <span class="ruby-value">read_timeout:</span> <span class="ruby-ivar">@read_timeout</span>,
                           <span class="ruby-value">write_timeout:</span> <span class="ruby-ivar">@write_timeout</span>,
                           <span class="ruby-value">continue_timeout:</span> <span class="ruby-ivar">@continue_timeout</span>,
                           <span class="ruby-value">debug_output:</span> <span class="ruby-ivar">@debug_output</span>)
  <span class="ruby-ivar">@last_communicated</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">on_connect</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">exception</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">s</span>
    <span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;Conn close because of connect error #{exception}&quot;</span>
    <span class="ruby-identifier">s</span>.<span class="ruby-identifier">close</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">raise</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-debug" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">debug</span><span
                                class="method-args">(msg)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Adds a message to debugging output</p>

                              <div class="method-source-code" id="debug-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2473</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">debug</span>(<span class="ruby-identifier">msg</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@debug_output</span>
  <span class="ruby-ivar">@debug_output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">msg</span>
  <span class="ruby-ivar">@debug_output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;\n&quot;</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="HTTP.html#method-i-D">D</a>
                            </div>

                          </div>

                  <div id="method-i-do_finish" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">do_finish</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="do_finish-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1714</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">do_finish</span>
  <span class="ruby-ivar">@started</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@socket</span>
  <span class="ruby-ivar">@socket</span> = <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-do_start" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">do_start</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="do_start-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1580</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">do_start</span>
  <span class="ruby-identifier">connect</span>
  <span class="ruby-ivar">@started</span> = <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-edit_path" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">edit_path</span><span
                                class="method-args">(path)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="edit_path-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1868</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">edit_path</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">proxy?</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">path</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-string">&quot;ftp://&quot;</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">use_ssl?</span>
      <span class="ruby-identifier">path</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-node">&quot;http://#{addr_port}#{path}&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">path</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-end_transport" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">end_transport</span><span
                                class="method-args">(req, res)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="end_transport-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2405</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">end_transport</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">res</span>)
  <span class="ruby-ivar">@curr_http_version</span> = <span class="ruby-identifier">res</span>.<span class="ruby-identifier">http_version</span>
  <span class="ruby-ivar">@last_communicated</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">closed?</span>
    <span class="ruby-identifier">debug</span> <span class="ruby-string">&#39;Conn socket closed&#39;</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-keyword">not</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@close_on_empty_response</span>
    <span class="ruby-identifier">debug</span> <span class="ruby-string">&#39;Conn close&#39;</span>
    <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">keep_alive?</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">res</span>)
    <span class="ruby-identifier">debug</span> <span class="ruby-string">&#39;Conn keep-alive&#39;</span>
    <span class="ruby-ivar">@last_communicated</span> = <span class="ruby-constant">Process</span>.<span class="ruby-identifier">clock_gettime</span>(<span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-constant">CLOCK_MONOTONIC</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">debug</span> <span class="ruby-string">&#39;Conn close&#39;</span>
    <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-keep_alive-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">keep_alive?</span><span
                                class="method-args">(req, res)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="keep_alive-3F-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2422</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">keep_alive?</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">res</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">req</span>.<span class="ruby-identifier">connection_close?</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@curr_http_version</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-string">&#39;1.0&#39;</span>
    <span class="ruby-identifier">res</span>.<span class="ruby-identifier">connection_keep_alive?</span>
  <span class="ruby-keyword">else</span>   <span class="ruby-comment"># HTTP/1.1 or later</span>
    <span class="ruby-keyword">not</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">connection_close?</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-on_connect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">on_connect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="on_connect-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1696</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">on_connect</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-send_entity" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">send_entity</span><span
                                class="method-args">(path, data, initheader, dest, type, &amp;block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Executes a request which uses a representation and returns its body.</p>

                              <div class="method-source-code" id="send_entity-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2319</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">send_entity</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">data</span>, <span class="ruby-identifier">initheader</span>, <span class="ruby-identifier">dest</span>, <span class="ruby-identifier">type</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">res</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">request</span>(<span class="ruby-identifier">type</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">initheader</span>), <span class="ruby-identifier">data</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">r</span>.<span class="ruby-identifier">read_body</span> <span class="ruby-identifier">dest</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>
    <span class="ruby-identifier">res</span> = <span class="ruby-identifier">r</span>
  }
  <span class="ruby-identifier">res</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sspi_auth" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">sspi_auth</span><span
                                class="method-args">(req)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="sspi_auth-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2446</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sspi_auth</span>(<span class="ruby-identifier">req</span>)
  <span class="ruby-identifier">n</span> = <span class="ruby-constant">Win32</span><span class="ruby-operator">::</span><span class="ruby-constant">SSPI</span><span class="ruby-operator">::</span><span class="ruby-constant">NegotiateAuth</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-identifier">req</span>[<span class="ruby-string">&quot;Proxy-Authorization&quot;</span>] = <span class="ruby-node">&quot;Negotiate #{n.get_initial_token}&quot;</span>
  <span class="ruby-comment"># Some versions of ISA will close the connection if this isn&#39;t present.</span>
  <span class="ruby-identifier">req</span>[<span class="ruby-string">&quot;Connection&quot;</span>] = <span class="ruby-string">&quot;Keep-Alive&quot;</span>
  <span class="ruby-identifier">req</span>[<span class="ruby-string">&quot;Proxy-Connection&quot;</span>] = <span class="ruby-string">&quot;Keep-Alive&quot;</span>
  <span class="ruby-identifier">res</span> = <span class="ruby-identifier">transport_request</span>(<span class="ruby-identifier">req</span>)
  <span class="ruby-identifier">authphrase</span> = <span class="ruby-identifier">res</span>[<span class="ruby-string">&quot;Proxy-Authenticate&quot;</span>]  <span class="ruby-keyword">or</span> <span class="ruby-keyword">return</span> <span class="ruby-identifier">res</span>
  <span class="ruby-identifier">req</span>[<span class="ruby-string">&quot;Proxy-Authorization&quot;</span>] = <span class="ruby-node">&quot;Negotiate #{n.complete_authentication(authphrase)}&quot;</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">err</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">HTTPAuthenticationError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;HTTP authentication failed&#39;</span>, <span class="ruby-identifier">err</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sspi_auth-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">sspi_auth?</span><span
                                class="method-args">(res)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="sspi_auth-3F-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2431</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sspi_auth?</span>(<span class="ruby-identifier">res</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@sspi_enabled</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">HTTPProxyAuthenticationRequired</span>) <span class="ruby-keyword">and</span>
      <span class="ruby-identifier">proxy?</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">res</span>[<span class="ruby-string">&quot;Proxy-Authenticate&quot;</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-string">&quot;Negotiate&quot;</span>)
    <span class="ruby-keyword">begin</span>
      <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;win32/sspi&#39;</span>
      <span class="ruby-keyword">true</span>
    <span class="ruby-keyword">rescue</span> <span class="ruby-constant">LoadError</span>
      <span class="ruby-keyword">false</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-transport_request" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">transport_request</span><span
                                class="method-args">(req) { |res| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="transport_request-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 2330</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">transport_request</span>(<span class="ruby-identifier">req</span>)
  <span class="ruby-identifier">count</span> = <span class="ruby-value">0</span>
  <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">begin_transport</span> <span class="ruby-identifier">req</span>
    <span class="ruby-identifier">res</span> = <span class="ruby-identifier">catch</span>(<span class="ruby-value">:response</span>) {
      <span class="ruby-keyword">begin</span>
        <span class="ruby-identifier">req</span>.<span class="ruby-identifier">exec</span> <span class="ruby-ivar">@socket</span>, <span class="ruby-ivar">@curr_http_version</span>, <span class="ruby-identifier">edit_path</span>(<span class="ruby-identifier">req</span>.<span class="ruby-identifier">path</span>)
      <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EPIPE</span>
        <span class="ruby-comment"># Failure when writing full request, but we can probably</span>
        <span class="ruby-comment"># still read the received response.</span>
      <span class="ruby-keyword">end</span>

      <span class="ruby-keyword">begin</span>
        <span class="ruby-identifier">res</span> = <span class="ruby-constant">HTTPResponse</span>.<span class="ruby-identifier">read_new</span>(<span class="ruby-ivar">@socket</span>)
        <span class="ruby-identifier">res</span>.<span class="ruby-identifier">decode_content</span> = <span class="ruby-identifier">req</span>.<span class="ruby-identifier">decode_content</span>
        <span class="ruby-identifier">res</span>.<span class="ruby-identifier">body_encoding</span> = <span class="ruby-ivar">@response_body_encoding</span>
        <span class="ruby-identifier">res</span>.<span class="ruby-identifier">ignore_eof</span> = <span class="ruby-ivar">@ignore_eof</span>
      <span class="ruby-keyword">end</span> <span class="ruby-keyword">while</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">HTTPInformation</span>)

      <span class="ruby-identifier">res</span>.<span class="ruby-identifier">uri</span> = <span class="ruby-identifier">req</span>.<span class="ruby-identifier">uri</span>

      <span class="ruby-identifier">res</span>
    }
    <span class="ruby-identifier">res</span>.<span class="ruby-identifier">reading_body</span>(<span class="ruby-ivar">@socket</span>, <span class="ruby-identifier">req</span>.<span class="ruby-identifier">response_body_permitted?</span>) {
      <span class="ruby-keyword">yield</span> <span class="ruby-identifier">res</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
    }
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">OpenTimeout</span>
    <span class="ruby-identifier">raise</span>
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">ReadTimeout</span>, <span class="ruby-constant">IOError</span>, <span class="ruby-constant">EOFError</span>,
         <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECONNRESET</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECONNABORTED</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EPIPE</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ETIMEDOUT</span>,
         <span class="ruby-comment"># avoid a dependency on OpenSSL</span>
         <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span>) <span class="ruby-operator">?</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSLError</span> <span class="ruby-operator">:</span> <span class="ruby-constant">IOError</span>,
         <span class="ruby-constant">Timeout</span><span class="ruby-operator">::</span><span class="ruby-constant">Error</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">exception</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">count</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">max_retries</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">IDEMPOTENT_METHODS_</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">req</span>.<span class="ruby-identifier">method</span>)
      <span class="ruby-identifier">count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
      <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@socket</span>
      <span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;Conn close because of error #{exception}, and retry&quot;</span>
      <span class="ruby-keyword">retry</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;Conn close because of error #{exception}&quot;</span>
    <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@socket</span>
    <span class="ruby-identifier">raise</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">end_transport</span> <span class="ruby-identifier">req</span>, <span class="ruby-identifier">res</span>
  <span class="ruby-identifier">res</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">exception</span>
  <span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;Conn close because of error #{exception}&quot;</span>
  <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@socket</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-identifier">exception</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-unescape" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">unescape</span><span
                                class="method-args">(value)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="unescape-source">
            <pre><span class="ruby-comment"># File net/http.rb, line 1853</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">unescape</span>(<span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;cgi/util&#39;</span>
  <span class="ruby-constant">CGI</span>.<span class="ruby-identifier">unescape</span>(<span class="ruby-identifier">value</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

